Common Java Collection Framework interview topics __java

Source: Internet
Author: User

1. Why the map interface does not inherit the collection interface. Set is an unordered set, and the duplicate element list is not allowed to be an ordered collection, and the combination map that allows duplicate elements and map is the set and value that it is considered to be the key is designed as a collection of key-value pairs, so there is no need to inherit the collection interface

The difference between 2.HashMap and Hashtable. Synchronous or thread-safe null key and Null value iteration value default capacity size

The difference between 3.comparable and comparator. The comparable interface is actually derived from the Java.lang package it has a compareTo (Object obj) method to sort objects The comparator interface is actually derived from the Java.util package it has a compare ( Object Obj1, Object Obj2) method to sort objects

4. How to sort the list of object. To sort the objects array, we can use the Arrays.sort () method if we want to sort the objects collection, we need to use the Collections.sort () method

5. The difference between fail-fast and fail-safe. Fail Fast reports any failure quickly. Whenever any problem triggers the fail fast system fails in the Java fail Fast iterator, iterations objects collections sometimes have concurrent modification exceptions that can occur for 2 reasons if a thread is iterating over a collection, And another thread tries to modify the collection at the same time after calling the Remove () method, how do we try to modify the collection object

6. The distinction between iterator, Listiterator and enumeration. The enumeration interface starts with the Java1.2 version, so enumeration is the interface of the legitimate specification enumeration uses the elements () method iterator all Java collection classes are implemented Iterator use the Iterator method iterator can only go in one Direction listiterator only the class of the list type implemented Listiterator use Listiterator () method

What is the difference between Set and list in 7.Java? Set is a set that does not allow duplicate elements to exist set without index set only allows a null value set has class: HashSet, Linkedhashmap, TreeSet list indexed list allows n null values list can be displayed in insert order List has class: Vector, ArrayList, LinkedList

8. What is the difference between ArrayList and vectors? Vector is introduced in the first version of Java, that is, the vector is a legitimate canonical class ArrayList introduced in the Java1.2 version, is part of the Java Collection Framework vector is synchronized ArrayList is not synchronized

9. What class implements the list interface. ArrayList LinkedList Vector

10. What class implements the set interface. HashSet Linkedhashset TreeSet

11. How to ensure a collection thread safety. Vectors, Hashtable, Properties, and Stack are all synchronized classes, so they are both thread-safe and can be used in a multithreaded environment using the Collections.synchronizedlist (list) method, The list class can be guaranteed to be thread safe using the Java.util.Collections.synchronizedSet () method to ensure that the set class is thread safe

12. Whether you can add null elements to TreeSet or hashset. You can add a null TreeSet to the HashSet and also allow a null value

13. Explain the following collection interface inheritance relationship.

Which design pattern is 14.Iterator compliant. Iterator design pattern

15.HashSet the implementation of which data structure. HashSet internal implementation of the HashMap

16. Why Collection cannot inherit cloneable and Serializable. The list and set unique inheritance Collection interface SortedMap inherits the Map interface

The importance of the 17.hashCode () and Equals () methods. How to use them in Java. The hashcode () and Equals () methods are defined in the "Object" class if the Equals () method returns True when comparing 2 objects, then the return value of hashcode () must be the same

The difference between 18.array and ArrayList. Array is similar to object collection type, size fixed ArrayList is a set of homogeneous and heterogeneous elements

19. What is a Properties class. Properties are subclasses of Hashtable. It is used to maintain a list of values where their keys and values are string types

20. How do I convert a string to ArrayList? Using the Arraylist.toarray () method

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.