Web Analytics Made Easy -
StatCounter JAVA sort String Array, no case - CodingForum

Announcement

Collapse
No announcement yet.

JAVA sort String Array, no case

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • JAVA sort String Array, no case

    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:
    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
    My Website
    010100010011110101110100011011110111000001101000

  • #2
    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

    PHP Code:

    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]);
            }
        }

    Spookster
    CodingForum Supreme Overlord
    All Hail Spookster

    Comment


    • #3
      Thanks
      My Website
      010100010011110101110100011011110111000001101000

      Comment

      Working...
      X