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

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

黄舟
Release: 2017-01-22 15:10:54
Original
1709 people have browsed it

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));
   }
}
Copy after login

The output result of the above code is:

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

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)!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template