Online Java Compiler By
JavaTpoint.com
import java.util.*; public class CollectionsMaxExample4 { public static void main(String[] args) { //Create collection List
list = new ArrayList
(); //Add values in the list list.add("Java"); list.add("COBOL"); list.add("PHP"); list.add("Ruby"); list.add("XML"); //Comparing using natural ordering System.out.println("Maximum Element is: " + Collections.max(list)); List
iList = Arrays.asList(-20, -10, -100, -140, -250); Integer max = Collections.max(iList); System.out.println("Maximum Value is: "+max); } }
Output