July 05, 2013

Java Program to sort List in alphabetical order

Write a Java Program to sort List in alphabetical order




import java.io.*;
import java.util.*;
class alphabet
{
  public static void main(String args[])throws IOException
    {
      BufferedReader st=new BufferedReader(new InputStreamReader(System.in));
      String str;
      System.out.println("Enter the string ");
      str=st.readLine();
      char[] charArray = str.toCharArray();
      Arrays.sort(charArray);
      String nstr = new String(charArray);
      System.out.println("The sorted string is "+nstr);
    }
}



OUTPUT


C:\Program Files\Java\jdk1.5.0\bin>java alphabet

Enter the string
prajakta
The sorted string is aaajkprt

No comments:
Write comments