Java learning Note 1 -- set and java note set

Source: Internet
Author: User

Java learning Note 1 -- set and java note set

1. What is a set?

A set is a set of objects, just as an array is a set of numbers. A collection is a container that can store objects (different types of objects can be used ).

Ii. Advantages of a set (Why use a set)

Of course, in java, Arrays can be used to store a group of identical objects. However, there are two disadvantages for storing objects in arrays (set advantages ):

Iii. collection implementation

Java integration is implemented by two interfaces:CollectionAndMap, Collection has two sub-interfaces:SetAndList.

 

Collection Interface

| ------- List Interface

| ------- ArrayList class (similar to an array), sort list class (similar to a linked list), and Vector class (thread-safe, but old, not commonly used)

| ------- Set Interface

| ------- HashSet, LinkedHashSet, TreeSet

 

Map Interface

| ------- HashMap, LinkedHashMap, TreeMap, Hashtable

 

Features of each interface:

Set: The elements are unordered and cannot be repeated. SortedSet is a Set that sorts elements in ascending order.

List: The elements are ordered and can be repeated. Provides an index-based access method. It can be viewed as a "dynamic array ",

Map: Key-value pairs with ing relationships "key-value. A key corresponds to a value, which is used to find the value. Therefore, the key cannot be repeated, and the value can be repeated.

 

Inheritance tree for the Collection interface:

 

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.