To sort elements of an array list, we use the sort() method of the Collections class. In order to use it, we must import the java.util.Collections package first. By default, the sorting occurs either alphabetically or numerically in ascending order. For example,
Output