Composition and classification of _01_ set frame of Set frame

Source: Internet
Author: User

The most common is ArrayList linkedlist hashset HashMap

Why are there so many containers?

Because each container has a different way of storing data

This storage method is called: Data structure.


The commonality of the set

/* Collection defines the common features of the set framework.
	1, add (e);

AddAll (collection);
	2, delete remove (e);
	RemoveAll (collection);

Clear ();
	3, Judge.
	Contains (e);

IsEmpty ();
	4, obtain iterator ();

Size ();
	5, get the intersection.

Retainall ();
	6, Set Variable group.



ToArray (); The parameter type of the 1,add method is object.

To make it easier to receive any type of object.
2, the collection is stored in the object's reference (address) what is an iterator.
is actually the way the collection takes out the elements.

Like a clip in a doll-catching game machine.
An iterator is a way of fetching, directly accessing elements in a collection.
So the iterator is described through the form of an inner class.




Gets the object of the inner class through the container's iterator () method.
	* * Class Collectiondemo {public static void main (string[] args) {method_get ();

		public static void Method_get () {ArrayList Al = new ArrayList ();
		1, add elements.
		Al.add ("Java01");//add (Object obj);
		Al.add ("Java02");
		Al.add ("java03");

		Al.add ("Java04");

		/* Iterator it = al.iterator ();//Get an iterator to take out the elements in the collection.
		while (It.hasnext ()) {SOP (It.next ());
		} */For (iterator it = Al.iterator (); It.hasnext ();)
		{SOP (It.next ());

		The public static void Method_2 () {ArrayList al1 = new ArrayList ();
		Al1.add ("Java01");
		Al1.add ("Java02");
		Al1.add ("java03"); AL1.add ("Java04");

		ArrayList Al2 = new ArrayList ();
		Al2.add ("java03");
		Al2.add ("Java04");
		Al2.add ("java05");

		
		Al2.add ("java06");
		Al1.retainall (AL2);//Go intersection, AL1 only preserves the same elements as Al2.

		Al1.removeall (AL2);
		SOP ("Al1:" +al1);




	SOP ("Al2:" +al2); public static void Base_method () {//Create a collection container. A subclass that uses the collection interface.

		ArrayList ArrayList al = new ArrayList ();
		1, add elements.
		Al.add ("Java01");//add (Object obj);
		Al.add ("Java02");
		Al.add ("java03");

		Al.add ("Java04");
		Prints the original collection.


		SOP ("Original set:" +al);
		3, delete the element.
		Al.remove ("Java02");


		Al.clear ()//Empty the collection.
		4, judge the element.
		SOP ("JAVA03" exists: "+al.contains" ("java03")); SOP ("Whether the collection is empty.)


		"+al.isempty ()); 2, get the number.
		Collection length.

		SOP ("Size:" +al.size ());
		Prints the changed collection.

	SOP (AL);
	public static void Sop (Object obj) {System.out.println (obj); }
}


Iterators


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.