
Write a java program that takes a list of words from the command line and prints out the arguments in an alphabetically sorted order

Hi Friend,
Try the following code:
import java.util.*;
class SortList
{
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
System.out.println("Enter List Elements: ");
ArrayList<String> list=new ArrayList<String>();
for(int i=0;i<5;i++){
String st=input.next();
list.add(st);
}
System.out.println("ArrayList Elements in Sorted order: ");
Collections.sort(list);
for(int i=0;i<list.size();i++){
System.out.println(list.get(i));
}
}
}
Thanks
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.