[Java] Collection framework description, hashtable, arraylist, and vector records

Source: Internet
Author: User
Framework Overview

The standard definition of a collection framework is a unified standard architecture defined for the expression and operation set. Any collection framework contains three main parts: External interfaces, interface implementation, and set calculation algorithms ."


According to my understanding, in the most popular words, we use the structure (queue, stack, tree, and map) in the data structure to install the data types used in various programming in a general sense, in a box. Then, this algorithm is used to sort, search, insert, and return data in the box.


In this way, the benefits of the framework are obvious. You do not need to design unique algorithms and operations for the data of the current program each time. You do not need to care about the underlying design of the program so that you can focus more on the overall aspects of the program, the quality and speed of code writing are better.


Java Collection

The Java Collection framework is a Java programming framework developed based on the above definition.

The collection interface is a basic interface that provides methods such as adding, deleting, determining whether it is null, clearing, iteration, and returning an array.


List, set, and map are the three most important interfaces in this collection system. The list and set interfaces inherit from the collection interface and perform some specific extensions of different types. Map associates "key-value.


List implements the arraylist and linklist. From the name, we can see that an array implements a linked list. The list interface puts the data in an orderly manner into the container and does not allow duplication. The specific implementations of set include hashset and treeset. Unlike the list interface, object elements in the Set interface cannot be repeated. The map interface is an interface that associates "key-value", that is, establishing a ing relationship. For example, the key = "login window" value = frmlogin, that is, each key corresponds to a value, therefore, keys cannot be repeated, values can be repeated, and put and set operations can be performed.


 

Ordered or not

Allow repeated Elements

Collection

No

Yes

List

Yes

Yes

Set

Abstractset

No

No

Hashset

Treeset

Yes (Binary Tree sorting)

Map

Abstractmap

No

Use Key-value to map and store data,

The key must be unique and the value can be repeated.

Hashmap

Treemap

Yes (Binary Tree sorting)

In addition to these interfaces, there are some legacy Java containers.

Array vector, add an object through addelement (), use elementat () to retrieve it, and query the number of currently saved objects size (); the hashtable uses put and set to set and retrieve the associated key values.

// Hashtableprivate static hashtable <string, jframe> table = new hashtable <string, jframe> (); table. get (STR); table. set (STR, FRM); // arraylistprivate arraylist <printwriter> printwriter = new arraylist <printwriter> (); printwriter. add (printwritertoclient); // linklistprivate comment list <string> msglist = new comment list <string> (); msglist. addfirst (stringfromclient); If (! Msglist. isempty () {S = (string) msglist. removelast (); txtcontentext. append (S + "\ n");} // vectorvector vecfields = new vector (); vecfields. addelement ("string_test_sample"); // hashsetset hashset = new hashset (); hashset. add (new string ("AAA"); // Add (object) add element (object); addall (Collection) Add a collection ); remove (object) deletes a specified Element (object); removeall (Collection) deletes a specified collection; size () capacity; isempty () determines whether it is null, that is, if [] or size () = 0, true or false is returned. If contains (object) is used to determine whether an element (object) is in a collection, true or false is returned. If containsall (Collection) is used) determines whether a collection is included; clear () is cleared, so that size () = 0; toarray () is converted into an object []; iterator () is used to construct an iterator, used to output elements in a hashset.

Which set interface is used depends on the data size, type, and Operation Method in the program, so as to select the optimal set, making program development the easiest and most efficient.

/*

* *****

* ***** 2013.6.30

* Http://blog.csdn.net/xyydyyqf

*/


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.