Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    the Netherlands
    Posts
    215
    Thanks
    0
    Thanked 0 Times in 0 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
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,280
    Thanks
    4
    Thanked 83 Times in 82 Posts
    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
    CodingForums Supreme Overlord
    All Hail Spookster

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    the Netherlands
    Posts
    215
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks
    My Website
    010100010011110101110100011011110111000001101000


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •