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
- Vector trimToSize() method in Java with Example
- Stack trimToSize() method in Java with Example
- StringBuffer trimToSize() method in Java with Examples
- StringBuilder trimToSize() method in Java with Examples
- ArrayList of ArrayList in Java
- Java.util.ArrayList.addall() method in Java
- Arraylist.contains() in Java
- ArrayList in Java
- Java.util.ArrayList.add() Method in Java
- Java.util.Arraylist.indexOf() in Java
- Reverse an ArrayList in Java
- Arraylist lastIndexOf() in Java with example
- ArrayList isEmpty() in Java with example
- Initialize an ArrayList in Java
- Get first and last elements from 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.