Java Basics---Collections

Source: Internet
Author: User

CollectionFrameFace Test1. The difference between Collection and collections. The difference.

Collections is a   java .util class, It contains various relevant A static method that sets the operation.

Collection is a Java . Util under the interface, it is a variety of Collection the parent interface of the structure is 2. List, Set, Map inherit from Collection interface interface?

List,set is Map is not

3. The difference between ArrayList and vectors. The difference.

I. Synchronicity: Most methods of vectors have the ability to synchronize, so vectors are thread-safe, that is, vectors are synchronous. In addition to the two methods used only for serialization, there is no ArrayList method with the ability to perform synchronously. So ArrayList are not thread-safe, not synchronous.

Two Execution efficiency: Because vectors are synchronous, and ArrayList are not synchronous. So the ArrayList is much more efficient than a Vector.

Three. Data growth: Both vectors and ArrayList support dynamic arrays that can grow as needed. The ability to dynamically increase or decrease its size. When growth is needed, vectors grow by default to the original, while ArrayList is half the original. Four If you are not specifically required to use synchronization in use, you should select ArrayList. Choosing ArrayList is faster and higher performance than choosing Vertor.

4. Why ArrayList can replace Vector?

You can use the synchronization method provided in collections to convert ArrayList to a synchronized collections.synchronizedlist (list<t> List) so ArrayList can replace the Vector.

5. The difference between ArrayList and LinkedList? The difference?

in the " Collection There are two general list implementations in the framework: ArrayList and LinkedList. Which of the two List types to use depends on your specific needs. If you want to support random access without having to insert or drop elements at any point except the trailer, ArrayList provides an optional collection . However, if you want to frequently add and remove elements from the middle of the list, and as long as the sequential access list element, then the LinkedList implementation is better. General differences between ArrayList and LinkedList:

1. ArrayList is a data structure based on dynamic array, LinkedList data structure based on linked list. When you use the Get method to access any element in a list (random access), it is faster than LinkedList.

2. For random access to get and set, ArrayList is definitely better than LinkedList because LinkedList is moving the pointer.

3. Add and Remove,linedlist are the dominant for new and deleted operations because ArrayList is moving the data.

6. The difference between HashMap and Hashtable.

A Synchronization: Most methods of Hashtable are synchronous, so Hashtable is thread-safe. The HashMap method does not have the ability to synchronize, so HashMap is not thread-safe.

Two Execution efficiency: Because the Hashtable is synchronous, the execution efficiency is compared to the bottom. Hahsmap is not synchronous, so execution efficiency is faster than Hashtable execution.

Three You can also use collections. Synchronizedmap (map<k,v> m) converts HashMap to thread-safe. Four If you are not specifically required to use synchronization in use, you should select HashMap. Choosing HashMap is faster and higher performance than choosing Hashtable. Five Value: Only HASHMAP can let you use NULL as a key or value for the entry of a table. HashTable not to be.


Java Basics---Collections

Related Article

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.