Java basic review: Collection framework

Source: Internet
Author: User

Why use a set?

Object-oriented language (OSS) Stores objects to facilitate operations on multiple objects. A set of objects is the most common method for storing objects.

Collection class features:
A set is only used to store objects. The length of a set is variable. A set can store different types of objects. The composition and classification of the Collection framework are as follows:

The following are some of the most commonly used features:

List: The most common interface. This interface can be used to expand the Collection interface in large quantities and the content in it can be repeated.

Set: the Collection interface is not extended, and repeated content cannot be stored in it.

Map: Map is the largest interface for storing a pair of values, and elements in the interface appear in pairs, key-> value

Iterator: the output interface of the set. It is used to output the content in the set and can only perform one-way output from front to back.

 

Two interfaces of the Collection class:

Java Collection classes are derived from two interfaces;

Collection:

Set: duplicate objects cannot be stored.

List: stores duplicate objects in an ordered manner.

Queue: Queue

SortedSet: sorts the set data.

Map:

SortedMap: sorts the set data.

Import java. util. arrayList; import java. util. collection; import java. util. iterator; public class CollectionDemo {public static void main (String [] args) {Collection c = new ArrayList (); // add to add element c. add ("A"); c. add ("well"); c. add (true); c. add (1); System. out. println (c); Collection c2 = new ArrayList (); // addAll add all elements in a set to c2.addAll (c); System. out. println (c2); // remove the specified Element c2.remove ("A"); System. out. println (c2); // iteration of the Set element for (Iterator it = c. iterator (); it. hasNext ();) {System. out. println (it. next ());}}}

 

 

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.