| | |
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,574
Reputation:
Solved Threads: 199
•
•
•
•
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 |
2dgraphics 3d @param affinetransform android api apple applet application arc arguments array arrays automation binary binarytree bluetooth byte chat chatprogramusingobjects class client code color compare component count database derby design detection eclipse eclipsedevelopment encryption error fractal game givemetehcodez graphics gridlayout gui guitesting helpwithhomework html ide if_statement image input integer interface j2me java java.xls javadesktopapplications javaprojects jni jpanel julia keytool keyword linux list loop macintosh map method methods mobile netbeans newbie object os pong problem producer program programming project projectideas read recursion replaysolutions rim scanner server set size sms sort sql string swing terminal threads transforms tree ui unicode web windows






