Java J2SE: Re-Learn the Java object container

Source: Internet
Author: User
Tags map class

Today is the first day of school, according to the lecture progress of the previous semester, it should be possible to start learning multithreading, but because of the teacher, may transfer a bit in and out, and give us a lecture on the Java object container, so this is why the topic for "re-learning."

This article directory:

  1. Main uses of the collection
  2. Single value class Collection: List class and set class
  3. Key-value pairs class collection: Map class

The main use of collections: collections are mostly used when querying data is returned. For example, to use JSP to do a student information management system, you need to return from the database to query the results of students, put these results into a collection, and then return through the method, in the display layer (view) can use JSP tags to display them.

Single-Value class collection: The single-value class collection consists of list and set, both of which inherit from the collection root interface. In these two large interface classes can be subdivided into several classes to implement the interface, mainly some of these:

List

Advantages

Disadvantages Characteristics
ArrayList Easy collection for quick random access Removal efficiency is low Asynchronous

LinkedList

Easy to insert and delete objects Low random access efficiency -----

List iterations: The iteration list can be iterated with the Get (Index) method, or by using the enhanced for loop foreach, or by using iterators.

Set

TreeSet Ordered, natural numbers are ordered, but the comparable interface must be implemented, overriding the Comoareto () method. Non-repeatable
HashSet Unordered, based primarily on equals and hashcode to determine whether the same object Non-repeatable

Set iterations cannot use the Get method and can be traversed using iterators and enhanced for loops.

Map

In class, the main HashMap, it is a set of key-value pairs, key keys are not allowed to repeat, a key can only correspond to one value, but a value can correspond to more than one key. Used to pass data between different pages. For example, the use of Request.setattribute ()/getattribute () in JSP is implemented using this kind of collection.

HashMap there is a method EntrySet () worth mentioning.

EntrySet ()

This method returns an attempt to set the mappings contained in this map, which, in layman's terms, is the set (contained in set) of an entity with a pair of <K,V> that can iterate over each HashMap entity using the iterative set method.

=========================end=================

The first blog feel Good egg pain, use is window Live Writer, code also did not post, the figure is not, a few sentences on the end, the total feeling that this editor is not so handy, as word, written like eating flies as not smooth, I am not suitable for blogging? Something so big on that.

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.