...

View Full Version : JAVA sort String Array, no case



chrisvmarle
02-13-2004, 08:39 PM
Hi all,

I can use a little help here
I have an array String[] tempnames, wich I want to be sorted alphabeticly not case sensitive.

Here's my current code:

import java.util.Arrays;

public class HelloWorld
{
public static void main (String[] args)
{
String[] tempnames = {"Chris","Remco","admin","moderator"};
Arrays.sort(tempnames);

for(int i=0;i<tempnames.length;i++)
{
System.out.println(tempnames[i]);
}
}
}


Thanks in advance
Greetz, Chris

Spookster
02-13-2004, 09:03 PM
This would probably be better in the Computer Programming forum unless of course this has to do with JSP/Servlets/EJB etc.

In any case you simply need to tell it to sort case insensitive




import java.util.Arrays;

public class HelloWorld
{
public static void main (String[] args)
{
String[] tempnames = {"Chris","Remco","admin","moderator"};

Arrays.sort(tempnames,String.CASE_INSENSITIVE_ORDER);

for(int i=0;i<tempnames.length;i++)
{
System.out.println(tempnames[i]);
}
}
}

chrisvmarle
02-14-2004, 12:22 PM
Thanks



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum