posted 9 years ago
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?
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?
posted 9 years ago
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.
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.
There are only two hard things in computer science: cache invalidation, naming things, and offbyone errors
posted 9 years ago
I suggest you check whether or not the List is empty. If it is, both get(0) and get(temperatures.size()  1) will fail.
SCJP 1.4  SCJP 6  SCWCD 5  OCEEJBD 6  OCEJPAD 6
How To Ask Questions How To Answer Questions
Hang a left on main. Then read this tiny ad:
The WEB SERVICES and JAXRS Course
https://coderanch.com/t/690789/WEBSERVICESJAXRS
