Java list intersection and set of differences set to repeat and set

Source: Internet
Author: User
Tags addall

First define two list

List List1 =NewArrayList (); List1.add ("1111"); List1.add ("2222"); List1.add ("3333"); List List2=NewArrayList (); List2.add ("3333"); List2.add ("4444"); List2.add ("5555");

Run:

           for (int0; i < list1.size (); i++) {               System. out. println (List1.  Get(i));           }

and set

List1.addall (LIST2);

Results:

1111 2222 3333 3333 4444 5555

Intersection

List1.retainall (LIST2);

Results:

3333

Subtraction

List1.removeall (LIST2);

Results:

1111 2222

No duplicate and set

List2.removeall (List1); List1.addall (LIST2);

Results:

1111 2222 3333 4444 5555

Java list intersection and set of differences set to repeat and set

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.