Hiya i have an array of objects called messageArray which is created by converting an ArrayList to an Array
The array has objects in it each called message and a message is made up of Now i want to sort the new Array which i have created by the sender by using bubble sort but not sure how can any help ?
At the moe the print out is
but after the sort i want
[ November 20, 2004: Message edited by: Jamie Cotton ] [ November 20, 2004: Message edited by: Jamie Cotton ]
Joined: Oct 12, 2000
why do it like that? And why care about the algorithm at all?
The easiest way would be to make your class Comparable and pipe the List into a SortedSet. It will then be sorted automagically.
Joined: Aug 05, 2002
the JDSL has some specific sorts (e.g. quicksort, mergesort), but not bubble sort. see if any of those give you good enough performance
Joined: Dec 06, 2001
Is there any reason you want to use bubble sort? I can understand if this is a homework assignment and the teacher has specified that you do so. However, if not, you should use Collections.sort() on the original ArrayList instead. In fact, why are you converting the ArrayList into an array? Also, if you want the list sorted, there are other collections that are better to use. TreeSet will put the items in a sorted order as you add them. You can also use an Iterator to iterate over the set (or even the original ArrayList), rather than converting it into an array.