Set collection about set and set comparison

Source: Internet
Author: User

The Containsall method is used to determine whether the set collection contains the entire contents of another collection.

Syntax Boolean containsall (collection<?> c)

Return value: Returns True if the Set collection contains all of the contents of the collection object specified by the parameter C, otherwise false is returned.

Parameter: C is another collection object to be judged.

Example This example first creates a set collection, adds some objects, and then creates a list collection with the same contents as the set collection, calling the Containsall method to determine whether the Set collection contains the contents of the list collection.

public static void Main (string[] args) {

Set set = new HashSet ();
Set.add (New Date ()); Add data to the list

Set.add ("Apple"); Add data to the list

Set.add (New Socket ()); Add data to the list

Set.add ("TV"); Add data to the list

List list=new ArrayList ();

List.add ("Apple"); Add data to the list

List.add ("TV"); Add data to the list

Boolean contains = Set.containsall (list);

if (contains) {

System.out.println ("Set collection contains the contents of the list collection");

} else {

System.out.println ("Set collection does not contain the contents of the list collection");

}

}

Set collection about set and set comparison

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.