| | |
Sorting Strings
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
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.
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
•
•
Join Date: Sep 2008
Posts: 1,658
Reputation:
Solved Threads: 206
•
•
•
•
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?
Views: 909 | Replies: 4
| Thread Tools | Search this Thread |
Tag cloud for Java
android api apple applet application apps arguments array arrays automation awt binary bluetooth businessintelligence busy_handler(null) card chat class classes client code collision component constructor database draw eclipse error event eventlistener exception file fractal game givemetehcodez graphics gui helpwithhomework html ide image input integer j2me jar java javafx javamicroeditionuseofmotionsensor javaprojects jmf jni jpanel jtree julia link linux list loop machine map method methods mobile netbeans newbie nls number object oracle parsing plazmic print problem program programming project recursion scanner screen server set sharepoint size smart sms socket sort sortedmaps sql string swing test textfield threads time transfer tree unlimited webservices windows






