Java后台通过Collections获取list集合中最大数、最小数

package com.jalor;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Jalor_20180728 {

	public static void main(String[] args) {
		List<Integer> rst2 = new ArrayList<>();
		rst2.add(1);
		rst2.add(2);
		rst2.add(3);
		rst2.add(8);
		rst2.add(0);
		Collections.max(rst2);
		Collections.min(rst2);
		System.out.println("max: "+ Collections.max(rst2));
		System.out.println("min: "+ Collections.min(rst2));
	}
}

实践是检验真理的唯一标准,结果如下

猜你喜欢

转载自blog.csdn.net/u013199013/article/details/81256453