/* linked list ascending order in java, how to sort linked list in java, how to sort linked list alphabetically java, Sorting A LinkedList Alphabetically in java */
import java.util.Collections;
import java.util.LinkedList;
public class AscendingOrderExample
{
public static void main(String args[]) throws InterruptedException
{
java.util.LinkedList ll = new java.util.LinkedList();
//Add elements to LinkedList
ll.add("A");
ll.add("C");
ll.add("E");
ll.add("D");
ll.add("B");
System.out.println("List before sorting: "+ll);
java.util.Collections.sort(ll); //sorting collection
System.out.println("List sorted in ascending order: "+ll);
}
}
Output:
import java.util.Collections;
import java.util.LinkedList;
public class AscendingOrderExample
{
public static void main(String args[]) throws InterruptedException
{
java.util.LinkedList ll = new java.util.LinkedList();
//Add elements to LinkedList
ll.add("A");
ll.add("C");
ll.add("E");
ll.add("D");
ll.add("B");
System.out.println("List before sorting: "+ll);
java.util.Collections.sort(ll); //sorting collection
System.out.println("List sorted in ascending order: "+ll);
}
}
Output: