Java tutorial
import java.util.ArrayList; import java.util.Comparator; import java.util.List; public class Main { public static void main(String[] args) { List<String> list = new ArrayList<>(); list.add("Java"); list.add("R"); list.add("CSS"); list.add("XML"); System.out.println("List: " + list); // Uses List.sort() method with a Comparator list.sort(Comparator.comparing(String::length)); System.out.println("Sorted List: " + list); } }