Answers for "how to sort collection in java"

2

how to sort collection in java

// Use Collections.sort()
import java.util.*;
ArrayList<String> al = new ArrayList<String>();
al.add("teach");
al.add("sleep");
al.add("geek");
Collections.sort(al);//just pass any collection object reference
System.out.println(al);//output :- [geek,sleep,teach]

or
/*
ArrayList<Integer> intal = new ArrayList<Integer>();
al.add(4);
al.add(8);
al.add(2);
Collections.sort(intal);
System.out.println(intal);//output :- [2,4,8]
*/
Posted by: Guest on May-04-2020

Code answers related to "how to sort collection in java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language