为什么Arrays.asList上一个int []返回一个List< INT []>和不是List< INT&GT ;? [英] Why does Arrays.asList on an int[] return a List<int[]>, and not a List<int>?

查看:90
本文介绍了为什么Arrays.asList上一个int []返回一个List< INT []>和不是List< INT&GT ;?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑这个code:

int[] tcc = {1,2,3};
ArrayList<Integer> tc = Arrays.asList(tcc);

针对上述情况,Java的抱怨说,它不能从转换列表&LT; INT []&GT; 的ArrayList&LT;整数GT;

这有什么错呢?

为什么列表&LT; INT []&GT; ,而不是列表&LT; INT&GT;

推荐答案

一个ArrayList只能容纳对象不语,如整型,而且由于INT!=整数你不能做你想要使用数组做什么原语,就这么简单。这将为整型数组,虽然工作。

An ArrayList can hold only objects not primitives such as ints, and since int != Integer you can't do what you're trying to do with an array of primitives, simple as that. This will work for an array of Integer though.

这篇关于为什么Arrays.asList上一个int []返回一个List&LT; INT []&gt;和不是List&LT; INT&GT ;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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