Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

Java Sorting Using sort()

import java.util.ArrayList;
import java.util.Collections;
class Main {
    public static void main(String[] args) {
        // Creating an array list
        ArrayList<Integer> numbers = new ArrayList<>();
        // Add elements
        numbers.add(4);
        numbers.add(2);
        numbers.add(3);
        System.out.println("Unsorted ArrayList: " + numbers);

        // Using the sort() method
        Collections.sort(numbers);
        System.out.println("Sorted ArrayList: " + numbers);

    }
}
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #Java #Sorting #Using
ADD COMMENT
Topic
Name
1+1 =