1List<Integer> myList = new ArrayList<>();
2
3for(int i = 0; i < 10; i++){
4 myList.add(i);
5}
6//gets highest number in the list
7int highestNumber = Collections.max(myList);
8
9System.out.Println(highestNumber);
10
11//output: 9
1import java.util.*;
2public class CollectionsMaxExample2 {
3public static void main(String[] args) {
4//Create collections lists.
5List<Integer> list = Arrays.asList(20, 10, 100, 140, 250);
6Integer max = Collections.max(list);
7System.out.println("Maximum element is: "+max);
8}