I want to delete the selected element in an array in java, for example deleting 3,5,8
in
int[]={3,2,5,6,4,8,9}
I want to delete the selected element in an array in java, for example deleting 3,5,8
in
int[]={3,2,5,6,4,8,9}
You can't. Arrays have a fixed length, and the only way to "delete" them would be to either use for example zero to mark a "deleted" entry, or to create a new smaller array and copy all but the "deleted" entries there.
Use ArrayUtils class to remove an element
array = ArrayUtils.removeElement(array,element)
Arrays cannot be resized, so you either create a new array and copy the desired elements from the old one (use System.arraycopy(..)
) for that, or better: use a Collection
such as ArrayList
or LinkedList
.