Easy Tutorial
❮ Java String Length Method Factorial ❯

Java Example - Finding Maximum and Minimum Values in a List

Java Examples

The following example demonstrates how to use the max() and min() methods of the Collections class to obtain the maximum and minimum values in a List:

Main.java File

import java.util.*;

public class Main {
   public static void main(String[] args) {
      List list = Arrays.asList("one Two three Four five six one three Four".split(" "));
      System.out.println(list);
      System.out.println("Maximum value: " + Collections.max(list));
      System.out.println("Minimum value: " + Collections.min(list));
   }
}

The output of the above code is:

[one, Two, three, Four, five, six, one, three, Four]
Maximum value: three
Minimum value: Four

Java Examples

❮ Java String Length Method Factorial ❯