There is an ArrayList which stores integer values. I need to find the maximum value in this list. E.g. suppose the arrayList stored values are : 10, 20, 30, 40, 50
and the max
value would be 50
.
What is the efficient way to find the maximum value?
@Edit : I just found one solution for which I am not very sure
ArrayList<Integer> arrayList = new ArrayList<Integer>();
arrayList.add(100); /* add(200), add(250) add(350) add(150) add(450)*/
Integer i = Collections.max(arrayList)
and this returns the highest value.
Another way to compare the each value e.g. selection sort or binary sort algorithm