ContainsAll List Java

前端 未结 5 1323
执念已碎
执念已碎 2021-01-07 23:48
     List a = new ArrayList();
     List b = new ArrayList();

     a.add(\"apple\");
     a.add(\"orange\");         


        
相关标签:
5条回答
  • 2021-01-08 00:19

    Because B is empty. A contains everything in B.

    0 讨论(0)
  • 2021-01-08 00:19

    Obviously a typo. b.add("orange") is what was meant.

    0 讨论(0)
  • 2021-01-08 00:20

    List.ContainsAll will return true if the list contains all of the elements within the target. Because B is empty A contains all the same elements as B.

    0 讨论(0)
  • 2021-01-08 00:21

    It's a matter of logic: does A contain all the elements inside B?

    This can be seen as for each element in B, does this element belong to A too?

    You can understand that the condition is true, since B is empty, there is no element to check: for each element in B, so for no element.

    0 讨论(0)
  • 2021-01-08 00:35

    Because b is empty. Therefore there is nothing in b that is not in a.

    0 讨论(0)
提交回复
热议问题