Forums Register Login

Sorting ArrayList and printing lowest value

+Pie Number of slices to send: Send
I have managed to work out how to print the highest value, but am unsure how to print the lowest one. so far I have this:


I assume that for the lowest value, the idea is the same, but i can't have a certain number in the brackets because the arrayList length is unknown.
Thinking out loud here, but is there anyway I can find out the length of this ArrayList and then put that number in the brackets?
+Pie Number of slices to send: Send
according to the API (which you should learn to read), you can call the size() method on the array to get the number of elements:

int size()
Returns the number of elements in this list.

so, if you have 5 elements, the last will be at index 4. in other words the last index will be at size() - 1.
+Pie Number of slices to send: Send
I suggest you check whether or not the List is empty. If it is, both get(0) and get(temperatures.size() - 1) will fail.
+Pie Number of slices to send: Send
OK thanks, i've managed to get it to work
+Pie Number of slices to send: Send
also have a look at the reverse(List), reverseOrder(), and reverseOrder(Comparator) methods in the Collections class.
You can combine these with sort to reverse the list.
What is that? Is that a mongol hoarde? Can we fend them off with this tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1834 times.
Similar Threads
compiling help
Dependent Combo Box
double value changes
Prime Factor Program
Problems printing a Treemap 2nd run
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 20:14:59.