Set can be seen as a container for storing object information.
About differences collections and arrays: the
length of the array is fixed, if you want to increase the length, you can only create a new array.
The collection length is variable, the data added theory unlimited, automatic expansion.
Type of the array element must be of the same type, such as String [] arr = [ "a ", "b", "c"];
collection elements may be of different types ArrayList <Object> arr = new ArrayList <Object> () ;
Java collection class consists of two main root interface Collection and the Map
Collection:
top level interface set of
three sub-categories
list ---------------- list is ordered, the subject has a lower, may be repeated of
the ArrayList
the ArrayList implements variable length array, allocate contiguous space in memory
- the advantages of: efficiency and random access through the elements of the element is relatively high
- disadvantages: the need to add and delete a large number of mobile elements of low efficiency, in accordance with the contents of the low search efficiency
LinkedList
LinkedList linked list storage.
- Advantages: inserting, deleting elements more efficient
- disadvantages: traversing element and a random access inefficiencies
Vector Vector class implements a dynamic array. ArrayList very similar and outdated
links and differences between Vector and ArrayList are:
- to achieve the same principles, the same function, are variable length array of structures, a lot of time
waiting can be interoperable
- the main difference between the two is as follows
▪ Vector is an early JDK Interface, ArrayList is a new interface alternative Vector
▪ Vector thread-safe, ArrayList speed of light heavy security, non-thread-safe
▪ need to increase the length of time, Vector default doubled, ArrayList% growth in 50
(1.5 + 1)
the Set -------------- --- sets are unordered, but should LinkHashSet exception, not the table below, can not be repeated!
Method (into and withdrawn Ji always coincide sequence) is similar to the operation data is not List, Set Interface presence get get () method does not exist!
HashSet: using Hashtable hash table storage structure
advantages: quick to add speed, fast query speed, delete speed
Disadvantages: disorderly
LinkedHashSet
using a hash table storage structure while using a linked list to maintain order in
order (the order of addition)
TreeSet
using binary tree (red black tree) storage structure
advantages: ordered (sorted ascending) List query speed faster than
drawbacks: query speed is not fast HashSet
queue queues is a special linear table, delete operation is allowed only at the front end of the table, perform insertion at the rear end of the table.
Map:
------------------------- HashMap
Key disorderly unique (the Set)
Value disorderly unique Ji (Collection)
TreeMap -------- -----------------
ordered hash speed is not fast
ConcurrentHashmap ---------------
concurrent related to the Map
HashMap and Hashtable links and differences :
- achieve the same principles, the same function, the underlying structure is a hash table, query speed,
in many cases used interchangeably
- the main difference between the two is as follows
▪ Hashtable is the interface provided by the earlier JDK, HashMap is a new version of the
JDK interface provided
▪ Hashtable class inherits Dictionary, HashMap implements the Map interface
▪ Hashtable is thread-safe, HashMap non-thread-safe
▪ Hashtable Ji allow null values, HashMap allows null values
Iterator interface:
Collection container class implements all the interface has a method for iterator returns an object that implements the Iterator interface.
▪ Iterator objects referred iterator to facilitate the realization of the traverse operation within the container elements.
▪ Iterator interface defines the following methods:
Boolean the hasNext (); // determines whether or not the element is traversed
Object next (); // returns the current cursor position and the cursor moves to the next element position
void remove (); // remove elements cursor to the left, which in the next after performing
// operation can only be performed once
collections tools
different collections and collection, the former category is a collection operation, which is a set of interfaces
collections provides static methods
addAll (): batch Add
Sort (): Sort
binarySearch (): binary search
Fill (): Alternatively
shuffle (): random order
reverse (): Reverse
generic:
generic type of the operation to solve the abnormal data generated Ji uniform.
Generics can use to better protect data types.
An example:
List new new = the arrayList the ArrayList ();
arrayList.add("abc");
arrayList.add(100);
for (int I = 0; I <arrayList.size (); I ++) {
String Item = (String) arrayList.get (I);
Log.d ( "generic test", "Item =" Item +);
}
operating results will crash, and reported: java.lang.ClassCastException: java.lang.Integer cAN bE Cast not to java.lang.String
arrayList which does not provide for generics, you can add different types of elements in it! When a chance and found int type String to type out when the incorrect report!
If we start ordained generic example:
List <String> = arrayList new new ArrayList <String> ();
then making arrayList.add (100); when the program will error during compilation!
Generic three different ways,
namely:
generic classes:
generic interface
generic method
also generic upper and lower
After waiting supplementary ..........