Java Container Some knowledge

Source: Internet
Author: User

First, Collection

1.static Method:

Collections.sort (list<t>): Implementing the List sort function

Collections.fill (list<t>, Object o): Change the contents of this container to a container that has already been added, all of which is this value

Second, List

ArrayList: Random retrieval is fast, but insertion, deletion time.

1.static Method:

Add (): adding elements

AddAll (list): Add a list in, if the array is to be converted to List, you can use Arrays.aslist (a []);

Clear: Clear the elements in the container

Set (Index a,object o): replace element

Size (): container sizes, need to have elements in case

IsEmpty (): Determines whether the container is empty

Contains (Object o): see if this element exists in the container

Iterator (): The bottom traversal of the container, Hasnext (): whether there is a next element, next (), is the next value.

Sublist (Index Low,index High): Part of the Intercept container comes out

Swap (List, A, B): Implements the Exchange value

LinkedList: Easy to insert and delete, but inconvenient and random search (sort by insert order)

List can be sorted using the Collections.sort method, the list container cannot exclude the same object and basic data type, and the data can be stored in this container as long as it belongs to this generic type.

Third, Set (the data stored is unique, for storing reference type objects, as long as the address is different, will also be stored in), the basic method is to cover the list above!

HashSet: The advantage is quick access. Storage is not written in the order of data, but is stored randomly!

TreeSet: The stored elements are sorted, and the String is sorted by a-Z and then A-Z.

Linkedhashset: Stores are sorted in the order in which they are entered.

Map main application and the mapping between list and Set key VALUE

static method:

Put (key, value); Storing data

  

HASHMAP: Convenient random access

TreeMap: Sort the elements well

Linkedhashmap: Storage by the sort of stored data

Hashcode and equals rewrite issues!!!!!!!

Other knowledge:

You can use the Aslist method to convert an array to a container: Arrays.aslist ("Once-three Fort ddd". Split (""));

String.case_insensitive_order

The comparable contains CompareTo

Java Container Some knowledge

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.