I shall send you to the Java™ Tutorials where you can read all about sorting, but for a List<String> you will probably end up using the appropriately-named method of the Collections class.
By the way, if you go through the String class API (click wherever the word String is underlined), you will find it has a static member which is a Comparator for case-insensitive sorting, should you need it.
Take a pick. If you don't see the difference, SearchFirst. There have been several threads about the difference between the two.
Thanks for willing to help. But it is possible for you to show me a example of how i could use any of this(I am really new in java)?
I am new to this website too and i was unable to search for an example. If there is already an example, could you give me a web link?
Vijitha Kumara wrote: . . . pointed by Campbell above (I have added it here too as that URL seems to be broken)
sorry about that; somehow the same link has been added twice, and that broke it.
Joined: Jan 11, 2011
Jesper de Jong wrote:Welcome to JavaRanch.
Create a class that implements interface java.util.Comparator for FreqAskQn objects. That would look like this:
You'll have to write some code inside the method to compare the two objects. The method should return < 0 if first comes before second, 0 if they are equal, and > 0 if second comes before first.
Then you can use the method Collections.sort(list, comparator) to sort the list.
Try writing the code yourself, and let us know if you got it to work or not.
Thank you very much! It works now.
Joined: Oct 13, 2005
I thought there were Strings in the List, which already implement Comparable<String>, in which case it would have been a really simple problemSorry if I was mistaken on that point.
But if you have a Question class, you will have to provide a Comparator<Question> or implement Comparable<Question> yourself, as people have already told you.