Java Container Class Summary

Source: Internet
Author: User

There are only two main types of Java container classes: collection and map.

Collection containers have only one element per slot.

The map holds the key-value pairs associated.

The collection sub-interface has list and set.

List: Stores elements in a specific order. Like ArrayList and LinkedList.

ArrayList: Good at random access.

LinkedList: Good at inserting, deleting, and moving elements.

Vector: Synchronization, security, low performance. The rest is as basic as ArrayList.

Set: Does not contain duplicate elements.

HashSet: Use hash function.

TreeSet: Use red and black trees. Orderly data arrangement

Linkedhashset: Use linked lists with hash functions.

Map subclasses have HashMap, Hashtable, and TreeMap

HASHMAP: Allows a null key and multiple null values.

HashTable: null keys and null values are not allowed. Thread Safety


Container class Output modes: Iterator, Listiterator, enumeration, and foreach

Iterator:

list<string> all = new arraylist<string> (); All.add ("Hello"); Iterator<string> iter = All.iterator ();  while (Iter.hasnext ()) {System.out.print (Iter.next ()); }

Foreach:

list<string> all = new arraylist<string> ();   All.add ("Hello"); for (String str:all) System.out.print (str);

Java Container Class Summary

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.