Online Java Compiler By
JavaTpoint.com
import java.util.*; public class CollectionsSortExample4 { public static void main (String[] args) { ArrayList
arr = new ArrayList
(); arr.add(new Student(101, "Java", "USA")); arr.add(new Student(103, "Ruby", "China")); arr.add(new Student(102, "Android", "India")); System.out.println("Data before sorted-"); for (int i=0; i
{ //Used for sorting in ascending order of roll number public int compare(Student a, Student b) { return a.rollno - b.rollno; } }
Output