Loading
View RSS Feed

Goldsonam's Blog

How To Sort Strings Alphabetically In Java?

Rate this Entry
Write a program to accept the following city name as argument in the command line and sort them in alphabetic order -
city name = Kolkata, Chennai, Mumbay, Delhi, Bangalore, Amedabad

Code:
import java.util.*;
import java.io.*;
import java.util.Arrays;

class city{
 public static void main(String args[])
{
 String names[] = new String[6];
 for(int i=0;i<6;i++)
 {
   names[i]= args[i];
 }
 Arrays.sort(names);
 System.out.println(Arrays.toString(names));
}
}

Submit "How To Sort Strings Alphabetically In Java?" to Digg Submit "How To Sort Strings Alphabetically In Java?" to del.icio.us Submit "How To Sort Strings Alphabetically In Java?" to StumbleUpon Submit "How To Sort Strings Alphabetically In Java?" to Google

Updated 02-14-2011 at 06:40 PM by Harsh

Categories
Java

Comments

  1. prafic's Avatar
    very simple and good one...



Disclaimer: Users of techforum4u.com are responsible for ensuring that any material they post (article, blog posts, images or other mulitimedia content) does not violate or infringe upon the copyright, patent, trademark, or any personal or proprietary rights of any third party, and is posted with the permission of the owner of such rights.Anyone who violates these rules may have their access privileges removed without warning.