日期:2014-05-18  浏览次数:20672 次

数组的比较?

Collection newCodes = Arrays.asList(array1);
Collection oldCodes = Arrays.asList(array2);

if (newCodes.containsAll(oldCodes) && oldCodes.containsAll(newCodes)) 
{

}
看到此代码觉得自己没有见过.麻烦大虾们.帮忙指点!!
1 . Arrays.asList();--不懂!!
2 . newCodes.containsAll(oldCodes);---不是很明白!!

------解决方案--------------------
不明白就要看JDK 的源代码,或者查看文档,看看那个方法是完成什么功能的!!!!
------解决方案--------------------
LZ偷懒:不查API
Arrays.asList()——把数组转成LIST;
containsAll();如果此 collection 包含指定 collection 中的所有元素,则返回 true。
------解决方案--------------------
asList
public static <T> List<T> asList(T... a)返回一个受指定数组支持的固定大小的列表。(对返回列表的更改会“直写”到数组。)此方法同 Collection.toArray 一起,充当了基于数组的 API 与基于 collection 的 API 之间的桥梁。返回的列表是可序列化的,并且实现了 RandomAccess。
此方法还提供了一个创建固定长度的列表的便捷方法,该列表被初始化为包含多个元素:

List stooges = Arrays.asList("Larry", "Moe", "Curly");