sort an array algorithm java code example
Example 1: sort array java
import java. util. Arrays;
Arrays. sort(array);
Example 2: Arrays.sort() in java
import java.util.ArrayList;
import java.util.Collections;
public class JavaSortArraylist
{
public static void main(String[] args)
{
ArrayList<String> al = new ArrayList<String>();
al.add("Bear");
al.add("Fox");
al.add("Deer");
al.add("Cheetah");
al.add("Anteater");
al.add("Elephant");
System.out.println("Before sorting ArrayList: " + al);
Collections.sort(al);
System.out.println("After sorting ArrayList in Ascending order: " + al);
}
}