Java Basic Knowledge Collation (vi)-collection class pen question __java

Source: Internet
Author: User

Organize the related pen questions of the collection class. (title answer, collation from the network, not necessarily correct, please note)


1. Briefly describe the storage performance and characteristics of the arraylist,vector, LinkedList.

The ArrayList and vector base use arrays to store data, add and delete slowly, check and change quickly, and they all allow you to index elements directly by ordinal.

ArrayList: Thread is not safe and fast

Vector: Thread-safe, usually less performance than ArrayList

and LinkedList use bidirectional linked list to realize storage, increase, delete fast, check, change slow


Another answer, we integrate:

A: ArrayList and Vector are mainly from two aspects.

I. Synchronicity: vectors are thread-safe, that is, synchronous, while ArrayList is not secure, not synchronized.

Two. Data growth: When growth is needed, the vector defaults to the original one, while ArrayList is half the original.

On HashMap and Hashtable mainly from three aspects.

I. Historical reasons: Hashtable is based on the old dictionary class, HashMap is an implementation of the map interface introduced by Java 1.2

Two. Synchronicity: Hashtable is thread-safe, that is, synchronous, and HashMap is not secure, not synchronized.

Three. Value: Only HashMap can let you use NULL as the key or value of a table entry


2. The difference between HashMap and Hashtable:

HashMap are lightweight implementations of Hashtable (not thread-safe implementations), they all implement the map interface,

The main difference is that HASHMAP allows null (NULL) key values (key), which is more efficient than Hashtable, because it is not thread-safe to have access to only one thread.

HASHMAP allows NULL to be used as a entry key or value, and Hashtable is not allowed.

Hashtable is thread-safe, that is, synchronous, and HashMap is not secure, not synchronized.

3. The difference between collection and collections

Collection is the superior interface of the collection class, and the inherited collection interface is mainly set and list

Collections is a helper class for collection classes, and he provides a series of static methods for searching, sorting, and thread-safe operations of various collections.


4. The elements in set cannot be duplicated, so what is the way to distinguish between duplicates or not? Is it with = = or equals ()? What's the difference between them?

The elements in set are not repeatable and are judged using the Equals () method.

= = is generally used to compare whether the base data type is equal, and equals () is used to determine whether two objects are equal.

Please refer to Java Basics Collation (c)-the difference between equals and = =

(Note: About this problem, online many of the answers are the same, to dialectical look, please pay attention to students.) )







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.