Recently went to interview, found himself a lot of basic knowledge are smattering, clearly his brain understand, understand the principle of knowledge point, but is said not to come out, also do not know is their ability to express the problem, or in fact, they do not master these knowledge, while the daily free time, good again to fill the foundation (upset, Say that some knowledge just learn when do not understand, but can do remember, use later understand, but can't remember. (All are looking at the online information, write the disorder, only as a personal note to use)
The Java Collection class provides a set of well-designed interfaces and classes that support the manipulation of a set of objects. The most basic interfaces within the Java Collection class are:
1, Collection: Represents a set of objects, each object is its child elements.
2, set (SET): No order, no duplicate elements of the collection.
3, List (queue): Sequential collection, and can contain repeating elements.
4, Map: You can map the key (key) to the value of the object, the key cannot be duplicated.
Java collection: A data structure, described in the C language of the mean struct, and in object-oriented programming, the data structure is described by a class and contains methods for manipulating the data structure.
In Java, designers have made some specifications and implementations of common data structures and algorithms, collectively referred to as the Java Collection framework.
Collection: The most basic set interface, a Collection represents a set of object (objects), some Collection allow the same elements together, but not the same, some can sort and some cannot be sorted;
JAVASDK does not provide classes directly inheriting from collection, and the provided classes are "sub-interfaces", such as list and set, that inherit from collection;
List interface: List is a sequential collection, using this interface to precisely control where each element is inserted, the user can use the index (the position of the element in the list, similar to the subscript of the array) to access the list of elements; list allows the same element to exist;
The implementation class of list: Linkedlist.arraylist,vector,stack;
1, linklist: Data structure is a chain of linear table (in the data structure note), he implemented the list interface, allowing null existence, in addition to its provided Get,remove,insert, method can make LinkedList can be used as stack (stack), queue ( Queue), or two-way queues (deque);
Note: Linklist does not have a synchronization method, if multiple threads access a list at the same time need to implement their own synchronous access, with synchronous code block;
2, ArrayList: The data structure is the linear table of order, he implements a variable size array, he allows all elements, including NULL, each ArrayList instance with a capacity, that is, the size of the array of storage elements this capacity automatically increases as new elements are added continuously, But the growth algorithm is not defined. When you need to insert a large number of elements, you can call the Ensurecapacity method before inserting to increase the capacity of the ArrayList to increase the efficiency of insertion (automatically increase the length of the judgment will be wasted time!) )。
Similarly: ArrayList does not use synchronization;
3, Vector:: Implemented a variable size array and ArrayList similar, but the difference is that the vector is synchronous access, which contains many of the traditional methods, these methods do not belong to the collection framework, the vector created by the iterator is being used, When another thread changes the state of the vector, it throws an exception and must be captured;
The old dynamic array, low efficiency, generally not used; Due to synchronization problem, ArrayList efficiency is higher than vector;
4, Stack: Inherit from the vector, the implementation of an advanced post-stack structure, just created is empty stack;
Set interface: In fact, set is collection, but the behavior is different, set does not save duplicate elements (with Equals ()); Each element that is stored in set is unique and does not guarantee the order of the elements;
1, TreeSet: The implementation of the set interface, the data structure is a red black book (self-balanced sort of binary tree, has not touched), is a set of variants, you can achieve sorting and other functions of the collection, he added elements to the collection, will automatically follow a certain comparison rules inserted into an ordered sequence of objects, and ensure that "ascending Arrange
2, HashSet: Implementation of the set interface, the bottom layer is based on HASHMAP implementation. The HashSet bottom uses HashMap to hold all the elements, all the elements placed in HashSet are actually saved by the HashMap key, and value stores a static class of object;
Java Collection Class--refresher notes