View a method that has no identical elements in two collections. Collections disjoint

Source: Internet
Author: User


When doing the project encountered a kind of situation, is to compare two sets of the same elements, after looking for data, found the collections class of the disjoint method
Here's a small example:

1 Importjava.util.Collections;2 ImportJava.util.HashSet;3 ImportJava.util.Set;4 5  Public classDemo {6 7      Public Static voidMain (string[] args) {8Set<string> Set1 =NewHashset<string>();9Set<string> Set2 =NewHashset<string>();Ten          OneSet1.add ("1"); ASet1.add ("1111"); -Set1.add ("2222"); -Set2.add ("222"); theSet2.add ("333"); -Set2.add ("111"); -         BooleanAAA =Collections.disjoint (Set1, Set2); - System.out.println (AAA); +     } -  +}

Run Result: true.

Parse: Returns True when there are no identical elements in the two collection. Returns False when there is the same element.

View a method that has no identical elements in two collections. Collections disjoint

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.