Rumah  >  Artikel  >  Java  >  Java 实例 - 查找 List 中的最大最小值

Java 实例 - 查找 List 中的最大最小值

黄舟
黄舟asal
2017-01-22 15:10:541614semak imbas

以下实例演示了如何使用 Collections 类的 max() 和 min() 方法来获取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));
   }
}

以上代码运行输出结果为:

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

以上就是Java 实例 - 查找 List 中的最大最小值的内容,更多相关内容请关注PHP中文网(www.php.cn)!

Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn