(collection) interview summary one

1. JAVA basics 1. The size of the eight basic
types, and their encapsulation class 2. Can ? Yes, it is supported after JAVA7, and the hashCode() of String is actually used to judge 3. The difference between equals and ==== compares the objects stored in the memory of two variables (stacks) ( heap) memory address, which is used to judge whether the addresses of two objects are the same . equals is used to compare whether the contents of two objects are the same. The equals inherited from Object still returns ==. Generally, subclasses of object need to override the equals method 4. What public methods does Object have? The Object clone() protection method implements shallow copying of objects. This method can only be called if the Cloneable interface is implemented. boolean equals(Object obj) is the same as ==, compares whether two objects are equal (memory address), subclasses generally override this method void finalize() This method is used to release resources Class<?> getClass() Get objects runtime type of






















int hashCode() Get the hashCode of the object. When rewriting the equals method, it is generally recommended to also rewrite the hashCode (the hashCode of the equals object must be equal)
void notify() This method wakes up a thread waiting on the object
void notifyAll() This method Wake up all threads waiting on the object
String toString() Generally subclasses override
void wait() This method makes the current thread wait for the object's lock. After calling this method, the current thread goes to sleep until the following event occurs.
void wait(long) (1) Other threads call the notify method of the object
void wait(long, int) (2) Other threads call the notifyAll method of the object
(3) Other threads call interrupt to interrupt the thread
(4) The time interval is up to

5. The role of hashCode
This method returns the hash code value of the object. If the two objects are equal (equals), the hashCode of the two objects must be equal. If the hashCodes of two objects are equal, the two objects may not be equal, or they may be equal.

The role of 5.hashCode
This method returns the hash code value of the object. If the two objects are equal (equals), the hashCode of the two objects must be equal. If the hashCodes of two objects are equal, the two objects may not be equal, or they may be equal.

6. Differences between ArrayList (dynamic array), LinkedList (linked list), and Vector (dynamic array)
(1) Synchronization: ArrayList and LinkedList are asynchronous, and Vector is synchronous
(2) Data growth: Both ArrayList and Vecotr are stored in the form of arrays. By default, Vector automatically doubles the length of the original array, while ArrayList is 50% of the original.
(3) The efficiency of retrieving, inserting, and deleting objects:
ArrayList and Vector take the same time to retrieve an object, or insert and delete an object at the end of the collection, which can be expressed as O(1). However, if elements are added or removed elsewhere in the collection, the time taken grows linearly: O(ni), where n is the number of elements in the collection and i is the index position at which the element was added or removed.
In LinkedList, it takes the same time O(1) to insert and delete an element anywhere in the collection. But it is slower when indexing an element, O(i), where i is the position of the index.

7. The difference between String, StringBuffer and StringBuilder

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326217663&siteId=291194637