Home  >  Article  >  Java  >  Java Example - Find the maximum and minimum values ​​in a List

Java Example - Find the maximum and minimum values ​​in a List

黄舟
黄舟Original
2017-01-22 15:10:541613browse

The following example demonstrates how to use the max() and min() methods of the Collections class to obtain the maximum and minimum values ​​in the 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("最大值: " + Collections.max(list));
      System.out.println("最小值: " + Collections.min(list));
   }
}

The output result of the above code is:

[one, Two, three, Four, five, six, one, three, Four]
最大值: three
最小值: Four

The above is a Java example - finding the maximum and minimum values ​​in the List. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn