Collections

  • Collections is a specialized static class under java.util that contains various static methods for collection operations. Provides a series of static methods to search, sort, and thread-safe various collections.

    public static void main(String[] args) {
        List list = new ArrayList();
        list.add(17);
        list.add(11);
        list.add(65);
        list.add(36);
    
        Collections.sort(list);
    
        System.out.println(list);//[11, 17, 36, 65]
    }
    Copy the code

Arrays

  • Arrays is a special java.util static class that contains Arrays of related operations that provide static methods for searching, sorting, copying, and so on.

    public static void main(String[] args) {
        int[] array = new int[]{11, 4, 23, 16, 3, 1, 4};
    
        Arrays.sort(array);
        System.out.println(Arrays.toString(array));//[1, 3, 4, 4, 11, 16, 23]
    }
    Copy the code