Sometimes we need to judge whether the B-linked list is a subset of the A-linked list, and we can use A.containsall (b) to determine that when the return value is true, the B-linked list is a subset of the A-linked list, and when the return value is False it indicates that the B-linked list is not a subset of the list A.
The experiment code is as follows:
PackageLearning;Importjava.util.ArrayList; Public classCationsall { Public Static voidMain (string[] args) {ArrayList<String> als =NewArraylist<string>(); Als.add (A); Als.add ("B"); ArrayList<String> ALSS =NewArraylist<string>(); Alss.add (A); Alss.add (C); System.out.println (Als.containsall (ALSS)); }}
Experimental Result: false
The experiment code is as follows:
PackageLearning;Importjava.util.ArrayList; Public classCationsall { Public Static voidMain (string[] args) {ArrayList<String> als =NewArraylist<string>(); Als.add (A); Als.add ("B"); ArrayList<String> ALSS =NewArraylist<string>(); Alss.add (A); System.out.println (Als.containsall (ALSS)); }}
Experimental Result: True
Let's look at the source code to understand the implementation of Containsall.
Public boolean containsall (collection<?> c) { Iterator<?> e = c.iterator (); while (E.hasnext ()) if (! contains (E.next ())) return false ; return true ;}
Java Method Containsall Learning