Java Container 1.Array Advantages: Efficiency, Type Identification, can hold Primitives Native Type Disadvantages: Create capacity fixed, not expanding. Considering ArrayList: Object array and native value array object array hold object ReferencePrimities array direct holdings four basic methods: equals (): Compare two arrays equal fill (): Fill arrays, only One word fill group binarysearch (): Find elements in a sorted array, does not support repeating elements asList (): Accept array, convert into a list container to copy an array: System.ArrayCopy (Source, Index, Destination, Index, Length ); When copying the object array, only reference is copied. The object itself will not be copied (shallow copy), and the primitives is the copy value .Equals () equal condition: must have the same number of elements and each of the same position elements An important goal is to distinguish between changes and unchanged things, and the local interface is realized, considering versatility.
2.Container automatically resizes the size of the size of the container: Storage Object Java is divided into two categories: Collection (List, SET) and MAP. Two types of differences are how much objects can be put each location. Collection adds an element with an Add () method, and the MAP adds an element with PUT (). Disadvantages: I don't know the type of object (1.5 adds a generic), only Object (Class), you can hold everything. Interfaces related to storage objects include Collection, SET, MAP, LIST, in an ideal case, most of which should only be derived with these interfaces, only to accurately indicate his determination type when creating a container.
3.List holds a set of elements objects in a specific order. The most important feature is orderly, which will ensure elements in a certain order. Basic methods: add (), get (), size (), item () ArrayList: an array that can extends automatically. Fast random access. LinkedList: Optimize sequential access to insert and delete elements in the middle. Can be used as stack, queue, deque. Listiterator: Only in ArrayList can only be used in ArrayList to traverse, not to insert and delete elements. In LinkedList, you can insert and delete the elements in the middle, traverse the list in both directions.
4. SET holds the objects different, that is, there is no repetition record. Objects To put it in the SET must define equals (). Hashset: Designed to optimize query speed. The object inside also defines the HashCode () method. Treeset: An ordered set, the underlying is a tree so that you can extract a ordered sequence from the SET. LINKEDHASHSET: An internal use of the LED table, the existing HashSet's query speed can save the elements to add in the order ( Insert order)
5. Map holds "Key-Value", "Relevance array", establishes contact in two object keys
6.IiteratorIitratot (iterator): The task is to allow customer programmers to move forward and rear and rear in an object sequence in an object sequence without knowing or not concerned about what the underlying sequence structure he has processed, and selects the objects. . Itrator is a "lightweight" object, and it is very small to create. Main method: iTerator (): Container call this method to an Iterator object next (): Get the next element object idea: Take all objects in the container, then process HASNext (): Whether the query sequence is in the query sequence There is also object remove (): Delete the last element object returned by the iterator 7.jdk1.5 to the new function A.Generics, similar to the C Templates (template) function, making the object when it takes out from Collection You don't have to do Downcasting, you have to ensure that the type of security does not have to be generics, returning a java.lang.Object object, you must first downcasting into a specific type. Generics guarantees the type of security. B.autoboxing / unboxing (Auto Parcel), Auto Convert Primitive (Original Type) Be Object (Object) makes the two no longer need cumbersome conversion, the compiler automatically detects and converts. C.Foreach, directly iterates objects in Collection, do not need to be converted into item. Very convenient to access all elements in a collection. D.TypeSafe Enumerations, enum is used to handle some list of data, such as: Week, Month, Color, etc. Enumeration means all values.