hi everyone..How can i print the items of an ArrayList alphabetically based on the field title of the items of the Arraylist??i have 12 objects in the list with different fields and i want to print the items based upon the title field.how can i do that??
Sort the ArrayList using the Collections.sort() static method. You'll need to write an implementation of java.util.Comparator that knows how to compare instances of your class; it can do so just by calling compareTo() on the "name" members. Then you can just iterate over the list and print it out.
Thnxs for the reply.I am beginning to see the picture now.But the fact is that i am completely unfamiliar with the sort method and the comparator.Lets say that my Arraylist is called L.If i do Collections.sort(L) what that would do???i just want to print the items based on the title field.there are other fields too but none of them are important.just the title field.the comparator how it is used in such a situation???can you please show me a txt file that shows the comparator actual use???Sorry if am being very annoying.:-(