To Sort the list we use the Collections Class in util Package
Ex:
package com.learn;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class Test {
public static void main(String[] args) {
List<String> normalOrder = new ArrayList<String>();
normalOrder.add("def");
normalOrder.add("abc");
normalOrder.add("ABC");
System.out.println("Before Sorting : "+normalOrder);
Collections.sort(normalOrder);
System.out.println("After Sorting :"+normalOrder);
}
}
So,In the above Program gives the following o/p
Before Sorting : [def, abc, ABC]
After Sorting :[ABC, abc, def]
Ex:
package com.learn;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class Test {
public static void main(String[] args) {
List<String> normalOrder = new ArrayList<String>();
normalOrder.add("def");
normalOrder.add("abc");
normalOrder.add("ABC");
System.out.println("Before Sorting : "+normalOrder);
Collections.sort(normalOrder);
System.out.println("After Sorting :"+normalOrder);
}
}
So,In the above Program gives the following o/p
Before Sorting : [def, abc, ABC]
After Sorting :[ABC, abc, def]
0 Response to "Sorting the List"
Post a Comment