我很想知道是什么:
new ArrayList<Something>(
Arrays.asList(
new Something("1"),
new Something("2")
)
);
返回?
它会返回包含这些Something
对象的ArrayList
,还是返回包含这些Something
对象List
的ArrayList
(即ArrayList<List<Something>>
(?
它将返回列表中的两个 Something,而不是包含列表的列表,因为您在 (( 中添加的集合中包含的集合元素将被添加到数组列表中,而不是作为集合的集合。
它不返回任何内容,您正在创建泛型ArrayList
的实例。
数组.asList ...这里 数组静态方法用于创建 Something 类的对象,因为ArrayList<>
的类型包含 Something 类。
最好打印 ArrayList 来检查结果。
for(Something something:myList){
//print the objects here
}