Arrays.asList() of an array

后端 未结 9 793
我寻月下人不归
我寻月下人不归 2020-11-27 15:41

What is wrong with this conversion?

public int getTheNumber(int[] factors) {
    ArrayList f = new ArrayList(Arrays.asList(factors));  
    Co         


        
9条回答
  •  南方客
    南方客 (楼主)
    2020-11-27 16:17

    This works from Java 5 to 7:

    public int getTheNumber(Integer... factors) {
        ArrayList f = new ArrayList(Arrays.asList(factors));
        Collections.sort(f);
        return f.get(0)*f.get(f.size()-1);
    }
    

    In Java 4 there is no vararg... :-)

提交回复
热议问题