java - What happens to the rest of an ArrayList once an object has been deleted within it? -


in java, when this:

alist[0].remove(); 

what happens rest of array list. of objects move 1 or stay same , there empty index @ [0]?

if not, there efficient way of moving each object's index closer down one?

to clarify mean more effecient:

you remove first index , iterate through arraylist , delete each object , re-assign new index, seems ineffecient , seems there should way have looked through @ javadoc page arraylist class , not see accomplish trying do.

assuming meant ask alist.remove(0)...

as documented oracle:

public e remove(int index)

removes element @ specified position in list. shifts subsequent elements left (subtracts 1 indices).

so remove require. however, may not consider implementation efficient since requires time proportional number of elements remaining in list. example, if have list 1 million items in , remove item @ index 0, remaining 999,999 items need moved in memory.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -