int[] i ={11,22,33};
List intlist = Arrays.asList(i);
for(Object o:intlist){
System.out.println(o.toString());
}
System.out.println("------------------------");
Integer[] ob = new Integer[] { 1, 2, 3, 4 };
List<Integer> oblist = Arrays.asList(ob);
for(int a:oblist){
System.out.println(a);
}
// oblist.add(111); 这句话加上会报错,java.lang.UnsupportedOperationException
System.out.println("------------------------");
/*当使用asList()方法时,数组就和列表链接在一起了.
* 当更新其中之一时,另一个将自动获得更新。
* 注意:仅仅针对对象数组类型,基本数据类型数组不具备该特性 */
ob[0] = 111;
for(int a:oblist){
System.out.println(a);
}
输出结果
[I@29453f44
------------------------
1
2
3
4
111
2
3
4
基本数据类型的数组不要用数组转LIST的方法。
转自:https://www.cnblogs.com/shanheyongmu/p/6364320.html