java.util Code Samples
- How do I get date, month, year values from the current date?
- How do I convert array to collection?
- How do I do a date add or substract?
- How do I calculate difference in days between two dates?
- How do I use StringTokenizer to split a string?
- How do I read file using Scanner class?
- How do I read user input from console using Scanner class?
- How do I get the current month name?
- How do I convert array to Set?
- How do I sort items of an ArrayList?
- How do I sort array values in descending order?
- How do I get the last day of a month?
- How do I convert collection into array?
- How do I convert milliseconds value to date?
Page of 6 |
Prev
|
Next
How do I trim the capacity of an ArrayList?
For minimizing the storage used by an ArrayList to the number of it's elements we can use the ArrayList.trimToSize() method call. In the code below we create an instance of ArrayList with the initial capacity set to 100. Later we only add five data into the list. To make the capacity of the ArrayList minimized we call the trimToSize() method.
