+ 4

Erase an element from Array

Hello! How can I erase or delete an element from an array?

17th Nov 2018, 9:22 AM
Vasile Radu Ion
9 Respuestas
+ 15
Vasile Radu Ion U can do it other way , if U don't know about pre-defined method for that : 1)make a duplicate array of it with (length of orginal array - 1) 2)run a loop on from 0 to (length of orginal array - 1) 3)if number to be deleted not comes then increase index of duplicate array & put elements of same index into it //give it a try ☺👍
17th Nov 2018, 11:29 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 5
You can use ArrayUtils for that.. a = ArrayUtils.removeElement(a, element) where a is nothing but array.
17th Nov 2018, 10:13 AM
Darshan Unadkat
Darshan Unadkat - avatar
+ 4
a = [1,2,3] a.remove(a[0]) print(a) output: [2,3] In python
17th Nov 2018, 9:25 AM
Mbrustler
Mbrustler - avatar
+ 3
Vasile Radu Ion i haven't worked much with java so im not sure but it should be in a simillar way
17th Nov 2018, 9:28 AM
Mbrustler
Mbrustler - avatar
+ 2
Thank you! but that code is in Python? I'm learning JAVA now. The sintax is the same?
17th Nov 2018, 9:27 AM
Vasile Radu Ion
+ 2
Thanks alot!!
17th Nov 2018, 9:33 AM
Vasile Radu Ion
+ 1
awesome Thank you!
17th Nov 2018, 10:28 AM
Vasile Radu Ion
+ 1
Just decrement the index of an array, happened in stacks for pop() operation
17th Nov 2018, 7:23 PM
Bipin Tatkare
Bipin Tatkare - avatar