Arrays.asList()不工作,因为它应该? [英] Arrays.asList() not working as it should?

查看:116
本文介绍了Arrays.asList()不工作,因为它应该?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个浮动[]和我想获得具有相同元素的列表。我可以做一个逐一添加的丑陋的东西,但我想用Arrays.asList方法。有一个问题,虽然。这工作:

I have a float[] and i would like to get a list with the same elements. I could do the ugly thing of adding them one by one but i wanted to use the Arrays.asList method. There is a problem though. This works:

List<Integer> list = Arrays.asList(1,2,3,4,5);

但是,这并不

int[] ints = new int[] {1,2,3,4,5};
List<Integer> list = Arrays.asList(ints);

该asList方法接受对我的知识的一个延伸可变参数参数是速记的数组。那么,为什么code的第二件返回列表&LT; INT []&GT; 而不是列表&LT; INT&GT;

和是有办法来纠正呢?

推荐答案

这个怎么样?

Integer[] ints = new Integer[] {1,2,3,4,5};
List<Integer> list = Arrays.asList(ints);

这篇关于Arrays.asList()不工作,因为它应该?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆