Java collection classes

Source: Internet
Author: User

The origin of the collection:

Storing multiple objects requires container-type variables to be stored, arrays and StringBuffer are container types, but StringBuffer can only store strings, not meet demand, and the length of the array is fixed and cannot adapt to changing needs, in order to accommodate this need, Java provides a collection class for us.

The difference between a collection and an array:

1. Length difference:

Arrays are fixed-length

Sets are variable-length

2, the content difference:

Arrays are stored in the same data type

The collection stores the objects, which can be different types of objects

3. The data type problem of the element:

Arrays can store both the base data type and the reference type

Collection can only store reference types

Inheritance architecture for Collections:

A collection is used to store multiple elements, but there are different requirements for storing multiple elements, such as requiring that elements not be duplicated, such as ordering. Java provides different sets of classes for different requirements. The data structure of these multiple collection classes is different, the structure is not important, it is important to be able to store things, and also can use these things, such as adding and deleting changes and so on. In this case, the collection classes are made up of generality, and we extract these commonalities upward and eventually we can form a set of inheritance architectures, such as:

In the above class diagram, the real line border is the implementation class , such as Arraylist,linkedlist,hashmap, and so on, the polyline border is an abstract class , such as Abstractcollection,abstractlist,abstractmap, and the point line border is the interface , such as Collection,iterator,list.

Java collection classes

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.