I have a List that stores different numbers, the maximum of them are elements under indices: 2; 4.
I want to print these 2 elements to the console - as the maximum numbers in the array, but the Collections.max () method returns only the first maximum value it finds, that is, only the element at index 2:
List<Integer> numbers = new ArrayList<Integer>();
numbers.add(5);
numbers.add(9);
numbers.add(50);
numbers.add(12);
numbers.add(50);
System.out.println(Collections.max(numbers));
|Output|
50
What should I use instead of method Collections.max() to find ALL maximum values?