1. 程式人生 > >java 陣列 math.max 方法取最大值

java 陣列 math.max 方法取最大值

package com;

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

public class Test {
public static void main(String[] args) {
//初始化陣列
List nums = new ArrayList();
nums.add(2);
nums.add(5);
nums.add(10);
nums.add(6);
nums.add(3);
//設定最大值Max
int Max = Collections.max(nums);
System.out.println(“Max = ” + Max);
}
}

public Integer getBoxNumto() {
     List<Integer> nums = new ArrayList<Integer>();
     for(NormalSample sample : normalSamples){
         nums.add(sample.getBoxNoto());
     }
     int Max = Collections.max(nums);
    return Max;
}