Skip to content

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!