| | |
Sorting Strings
![]() |
The String method compareToIgnoreCase should do the trick. For example:
That should give you a start anyway. Have a go and see what you can come up with.
java Syntax (Toggle Plain Text)
int result = string1.compareToIgnoreCase(string2); // here result < 0 if string1 > string2 // or result = 0 if string1 == string2 // or result > 0 if string1 < string2
That should give you a start anyway. Have a go and see what you can come up with.
There are no stupid questions, only those too stupid to ask for help.
echo is a web developer's best friend. > Can anyone tell me or give me a hint as to how am i going to sort the words
> in alphabetical order.
Look into the Collections#sort method which takes a
> in alphabetical order.
Look into the Collections#sort method which takes a
Comparator instance to facilitate custom sorting. I don't accept change; I don't deserve to live.
•
•
Join Date: Sep 2008
Posts: 1,532
Reputation:
Solved Threads: 191
•
•
•
•
The String method compareToIgnoreCase should do the trick. For example:
java Syntax (Toggle Plain Text)
int result = string1.compareToIgnoreCase(string2); // here result < 0 if string1 > string2 // or result = 0 if string1 == string2 // or result > 0 if string1 < string2
That should give you a start anyway. Have a go and see what you can come up with.
No, the compareToIgnoreCase method's documentation in the API states that it compares the two strings "lexicographically", meaning that they are compared according to where they would be placed in a dictionary. The documentation also states that locales are ignored, but I'm not entirely sure what they mean by that, perhaps accented characters as seen in French or the umlaut in German are not considered?
There are no stupid questions, only those too stupid to ask for help.
echo is a web developer's best friend. ![]() |
Similar Threads
- radix with strings of integers (C++)
- Rearranging and Sorting C strings. (C++)
- List View Sorting and Callback (C)
- sorting an array of string (C)
- sorting 2d arrays (C)
Other Threads in the Java Forum
- Previous Thread: How to make this sort of frame with SWING
- Next Thread: unexpected type.....why?
| Thread Tools | Search this Thread |
-xlint actionlistener android api applet application array automation bi binary blackberry block bluetooth character class client code compile compiler component consumer database desktop developmenthelp eclipse error fractal freeze ftp functiontesting game gameprogramming givemetehcodez graphics gui health html hyper ide image int j2me j2seprojects java javac javaee javaprojects jetbrains jni jpanel jtable julia learningresources lego linked linux mac main map method mobile myregfun netbeans nonstatic notdisplaying number online pearl printf problem program project qt researchinmotion rotatetext rsa scanner screen server set singleton sms sort spamblocker sql string swing system textfields thread threads time title tree tutorial-sample update variablebinding windows working xor






