Java finds maximum and minimum values in List for example
- 2020-07-21 07:45:30
- OfStack
The following example demonstrates how to use the max() and min() methods of the Collections class to get the maximum and minimum values in List:
/*
author by w3cschool.cc
Main.java
*/
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(" The maximum : " + Collections.max(list));
System.out.println(" The minimum value : " + Collections.min(list));
}
}
The output result of the above code operation is:
[one, Two, three, Four, five, six, one, three, Four]
The maximum : three
The minimum value : Four
I hope you found this article helpful