Skip to content
Advertisement

Tag: arraylist

Shrinking an ArrayList to a new size

Do I really need to implement it myself? Answer Create a sublist with the range of elements you wish to remove and then call clear on the returned list. This approach is mentioned as an idiom in the documentation for both List and ArrayList. Here’s a fully unit tested code example!

When to use LinkedList over ArrayList in Java?

I’ve always been one to simply use: I use the interface as the type name for portability, so that when I ask questions such as this, I can rework my code. When should LinkedList be used over ArrayList and vice-versa? Answer Summary ArrayList with ArrayDeque are preferable in many more use-cases than LinkedList. If you’re not sure — just start with

Advertisement