|
Java 实例 - 查找 List 中的最大最小值
以下实例演示了如何使用 Collections 类的 max() 和 min() 方法来获取List中最大最小值: 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
程序猿的技术大观园:www.javathinker.net
[这个贴子最后由 flybird 在 2020-01-27 16:33:00 重新编辑]
|
|