i have made an ArrayList (ie ArrayList one = new ArrayList() ). This list has 1 - 100 values (1 - 900) added to it. It works fine. How do i get the highest value from the array? I have been looking at the javasun basic tutorials and examples and cannot find what i need.
Well, there are two ways you could do it. Either sort the list (using Collections.sort()) and then take the value at the highest index, or scan through the list, looking at each item, remembering the largest item seen so far. The former is probably easier. The latter has better performance.
when i use Collection.sort(ArrayList) and get the results, it sorts in a non numerical order. instead of lowest first and highest last, it goes by first digits, so if there is 1, 2, 3, 121, 234 it sorts it like this: 1, 121, 2, 234, 3.
joseph [ March 02, 2005: Message edited by: joseph mcgratton ]
What type of objects are in your collection? Are they Strings? If so, then that's why they sort that way. Put Integer objects into the array and it will work almost as you expected (the sort order will be lowest to highest).
James Carman, President<br />Carman Consulting, Inc.
thankyou james for your help. it could be because they are strings. I cant remember why, but something would work with integers so i switch between strings and integers. now i know where the problem is, ill be ok.
If you open the box, you will find Heisenberg strangling Shrodenger's cat. And waving this tiny ad: