java

关注公众号 jb51net

关闭
首页 > 软件编程 > java > Java查List 中的最大最小值

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

投稿:wbb

这篇文章主要介绍了JAVA得到数组中最大值和最小值的简单实例,需要的朋友可以参考下

以下实例演示了如何使用 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

希望本篇文章对您有所帮助

您可能感兴趣的文章:
阅读全文