| | |
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,566
Reputation:
Solved Threads: 196
•
•
•
•
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 |
911 actionlistener addressbook android api append applet application array arrays automation binary block bluetooth character chat class client code component consumer csv database desktop developmenthelp eclipse error fractal ftp game gameprogramming givemetehcodez graphics gui html ide image integer j2me j2seprojects japplet java javaarraylist javac javaee javaprojects jni jpanel julia lego linked linux list loops mac map method methods mobile netbeans newbie number objects online oriented panel printf problem program programming project projects properties recursion replaydirector reporting researchinmotion rotatetext rsa scanner se server set singleton sms sort sql string swing test textfields threads time title tree tutorial-sample ubuntu update windows working






