Possible Duplicate:
How to sort an arraylist of objects java?
I have an arraylist that contains very large details i want to sort the data alphabetically but there is no method in arraylist class for sort. Please Help?
Possible Duplicate:
How to sort an arraylist of objects java?
I have an arraylist that contains very large details i want to sort the data alphabetically but there is no method in arraylist class for sort. Please Help?
Use Collections.sort, which is able to sort any List.
I'm assuming that you're talking about a list of strings, in which case you can simply call Collections.sort on your list to sort it alphabetically.
If you're referring to a list of instances of a class you created with an internal string field then you have two options:
Have the class implement the Comparable interface, then call Collections.sort on the list with no arguments other than the list itself.
Write a custom Comparator that works with your class, and pass an instance of it to the sort method as a second argument along with your list.
If alphabetical ordering is the 'natural' way in which instances of your class should be ordered, you should probably implement Comparable. If not, you should probably write a Comparator.
There is no sort method in arraylist But there is a sort method in Collections as ArrayList comes under the collections tree structure you can use the sort of method in collections.Here is the code Collections.sort(arrayList);