User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 425,866 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,483 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Sep 20th, 2004
Views: 26,603
This class will sort strings in alphabetical order.
java Syntax | 4 stars
  1. public class SortArrayString
  2. {
  3. public static void sortEm(String [] array, int len)
  4. {
  5.  
  6. int a,b;
  7. String temp;
  8. int sortTheStrings = len - 1;
  9. for (a = 0; a < sortTheStrings; ++a)
  10. for (b = 0; b < sortTheStrings; ++b)
  11. if(array[b].compareTo(array[b + 1]) >0)
  12. {
  13. temp = array[b];
  14. array[b] = array[b + 1];
  15. array[b + 1] = temp;
  16. }
  17.  
  18. }
  19. }
Comments (Newest First)
alpe gulay | Light Poster | May 16th, 2008
..its good to see how really sorting goes on!..
if we use java.util.Arrays.sort(array);
it makes us faster and easier!.,..
yah its much easier but this one is good to letting know your self on how sorting goes on!!
this help most students like me!!!..
well, its up to you on what you better used to be,.
the point is you understand how it goes like that and goes like this and so on and so for.....,;
cscgal | The Queen of DaniWeb | Mar 31st, 2006
Why did you have to register? Guests have the ability to view code snippets and comments.
agent_x91 | Newbie Poster | Dec 9th, 2005
Hah... I had to register to this website just to find out that I can use an already existing method to sort Strings into alphabetical order... thanks jwenting.
jwenting | duckman | Feb 9th, 2005
A far easier implementation is as follows:
public static void sortEm(String[] array, int len)
{
    java.util.Arrays.sort(array);
}
cscgal | The Queen of DaniWeb | Sep 20th, 2004
Thank you.
Post Comment

Only community members can submit or comment on code snippets. You must register or log in to contribute.

DaniWeb Marketplace (Sponsored Links)
All times are GMT -4. The time now is 5:51 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC