public static void main(String[] args) {Collection<String> col = new ArrayList<String>();Collection<String> cols = new ArrayList<String>();col.add("a");col.add("b");col.add("c");cols.addAll(col);cols.remove("b");cols.clear();System.out.println("col:"+col.toString());System.out.println("cols:"+cols.toString());System.out.println(col.contains(cols));boolean contains = col.containsAll(cols);if (contains) {System.out.println("Set集合包含List集合的內(nèi)容"+contains);} else {System.out.println("Set集合不包含List集合的內(nèi)容"+contains);}}為什么 結(jié)果是 true
1 回答

精慕HU
TA貢獻(xiàn)1845條經(jīng)驗(yàn) 獲得超8個(gè)贊
哈哈,去本地模擬了一下這個(gè)程序。也是有點(diǎn)懵的,然后去看了看這個(gè)方法的Api
Returns true if this collection contains all of the elements in the specified collection.
因?yàn)?cols 為空啊,所以 col 肯定包含了cols 中的全部,明白了嗎?
添加回答
舉報(bào)
0/150
提交
取消