Common methods for set of Java containers

Source: Internet
Author: User

The set does not contain the same elements, has hashset (hash, fastest lookup), TreeSet (in ascending order), Linkedhashset (in the sequence of input)

the following are common methods:

Import java.util.*;
public class Setoperations {

	/**
	 * @param args */public
	static void Main (string[] args) {
		//TODO Aut o-generated method Stub
		set<string> set1=new hashset<string> ();
		Collections.addall (Set1, "a b c D e F g h i K l J". Split (""));
		Set1.add ("M");
		System.out.println (Set1.contains ("M"));
		Set<string> set2=new hashset<string> (Arrays.aslist ("a B c D". Split (""));
		System.out.println (Set1.containsall (Set2));
		Set1.remove ("H");
		System.out.println (SET1);
		Set1.removeall (Set2);
		System.out.println (Set1);

	}




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.