+ 4
Erase an element from Array
Hello! How can I erase or delete an element from an array?
9 Antworten
+ 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 ☺👍
+ 5
You can use ArrayUtils for that..
a = ArrayUtils.removeElement(a, element)
where a is nothing but array.
+ 4
a = [1,2,3]
a.remove(a[0])
print(a)
output:
[2,3]
In python
+ 3
Vasile Radu Ion i haven't worked much with java so im not sure but it should be in a simillar way
+ 2
Thank you! but that code is in Python? I'm learning JAVA now. The sintax is the same?
+ 2
Thanks alot!!
+ 1
awesome Thank you!
+ 1
Just decrement the index of an array, happened in stacks for pop() operation