The trimToSize() method of ArrayList in Java trims the capacity of an ArrayList instance to be the list’s current size. This method is used to trim an ArrayList instance to the number of elements it contains.
Parameter: It does not accepts any parameter.
Return Value: It does not returns any value. It trims the capacity of this ArrayList instance to the number of the element it contains.
Errors and Exceptions: It does not have any errors and exceptions.
Below program illustrate the trimTosize() method:
The List elements are: Number = 2 Number = 4 Number = 5 Number = 6 Number = 11
- Stack trimToSize() method in Java with Example
- Vector trimToSize() method in Java with Example
- StringBuilder trimToSize() method in Java with Examples
- StringBuffer trimToSize() method in Java with Examples
- ArrayList of ArrayList in Java
- Java.util.ArrayList.addall() method in Java
- ArrayList in Java
- Arraylist.contains() in Java
- Java.util.ArrayList.add() Method in Java
- Java.util.Arraylist.indexOf() in Java
- Synchronization of ArrayList in Java
- Vector vs ArrayList in Java
- Arraylist lastIndexOf() in Java with example
- How to get ArrayList from Stream in Java 8
- Array of ArrayList in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.