PLease do the Following: 1. Insert your array to ArrayList as new ArrayList(array); 2. Use Collections.sort(arraylist) 3.Print Arraylist, You will get result I'm supposed to order an array of integers. the original array is:
looks pretty good, but hey, there are numbers in there that shouldnt be there?! I have no idea how I just lose some numbers and the compiler adds some instead...
here is the code i have:
Any help is greatly appreciated! Ben [ April 19, 2004: Message edited by: Ben Buchli ][/QB]
the original array is: --- looks pretty good, but hey, there are numbers in there that shouldnt be there?! I have no idea how I just lose some numbers and the compiler adds some instead... When I run your algorithm, the result isn't as you've reported - no new numbers are introduced to the array, but the ordering of the components definitely isn't quite sorted. As Zhengwu suggested, if you make that one small change to your algorithm, then I'm pretty sure you've got it figured out. As the aptly named Java Programmer pointed out, when you're not just programming to learn, making use of existing libraries to perform routine tasks such as sorting can save quite a bit of effort for more important things. Note that if you wanted to go the "use the existing libraries" route to sort an array, converting it into an ArrayList is unnecessary. The utility class java.util.Arrays includes methods for sorting any primitive array, as well as for sorting an array of Comparable objects.