Collections Sort List Java Code Example


Example: 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] */

Comments

Popular posts from this blog

Are Regular VACUUM ANALYZE Still Recommended Under 9.1?

Can Feynman Diagrams Be Used To Represent Any Perturbation Theory?