Collection System
A Data
- List Collection Storage data structure
<1> Stack Structure
Features: Advanced post-out
<2> Queue Structure
Features: Advanced First Out
<3> Array Structure
Features: Fast query, adding and deleting slow
<4> Linked list structure
Features: Delete quickly, query slow
Two List Interface
Java.util.List Interface (collection)extends Collection interface
features of the List interface:
Allow duplicate elements to be stored
is an ordered set (the order in which the elements are stored and the order in which they are taken out) 123 out 123
indexed, including some unique methods with indexes (there are three ways to traverse: iterators, enhanced for, normal for )
Unique methods with indexes:
- Add (int index, e e); add an element on the specified index
- E Remove (int index); removes and returns the element at the specified index
- E Set (index int, e e); modifies and returns an element on the specified index
- E get (int index); returns the element at the specified position in the list;
Attention:
When manipulating index methods, be sure to avoid index out of bounds exceptions
Indexoutofboundexception: index out of bounds exception, the collection will report
Stringindexoutofboundexception: String index out of bounds exception
Arrayindexoutofboundexception: Array index out-of-bounds exception
Three Arraylist<e> Collection
Characteristics:
The bottom is an array structure, query fast, and delete slowly;
Ordered collection
Allow storage of duplicate data
Four Vector Collection
Jdk1.0 appears, single thread, line Shuo complete
Five Linkedlist<e> Collection
Java.util.linkedlist<e> Collection implements List<e>
Characteristics:
The bottom is a doubly linked list structure, query slow, and delete quickly;
Access is ordered.
Allow repeating elements
LinkedList -specific methods:
Added method:
-
- void AddFirst (e e) inserts the specified element at the beginning of this list
- void push (e e) inserts an element at the beginning of this list. This method is equivalent to AddFirst (e e)
-
- void Addlist (e e) adds the specified element to the end of the list, equivalent to Add (e e);
method to delete:
-
- E Removefirst (); Remove and return the first element of this list
- E Removelast (); removes the last element from the returned list;
- E pop () removes and returns the first element of this list, which is equivalent to removefrist ()
Get the method:
-
- E GetLast (); gets the last element
- E getfrist (); gets the first element
- Boolean IsEmpty (); Determine if the list is empty
Six Set Set
Java.util.Set Interface (collection) extends Collection interface
features of the Set interface:
-
- Duplicate elements are not allowed
- no index, no normal for traversal
Seven Hashset<e>
Java.util.hashset<e> Set implements set interface
features of the Hashset<e> interface
-
- The underlying principle is a hash table (array + one-way list), query fast, and delete quickly
- Unordered collections, which can be stored in a sequence that is inconsistent with the order taken
Use Hashset<e> The only principle of storing elements: overriding the hashcode () method and the equals () method;
Use HashSet the Add method stores an element , the hashcode ()method is called automatically,and then the hash value of the elements in the collection is compared, and if there is no identical hash value, it is deposited. If the hash value has the same, then the equals () method is called, and the equality is determined, if the equality is not deposited, the unequal deposit
Eight Linkedhashset<e>
Java.util.LinkedHashSet Collection extends HashSet collection
Linkedhashset<e> Features:
-
- underlying principle: Hash table (array + unidirectional linked list)+ doubly linked list.
- A doubly linked list guarantees an orderly access to elements. But element requirements cannot be duplicated
Nine Hash value
is a decimal integer, with the operating system randomly given
You can use the method Hashcode in the object class to get the hash value
int hashcode () Returns the hash code value of the object;
Source:
public native int hashcode ();
Native: refers to a method implementation that invokes the local operating system
Ten Arraylist<e> methods for storing non-repeating elements in a collection:
- Boolean contains (Object O); method to determine whether the specified element is included
- will be ArrayList element traversal is added to the set collection
- Use the construction method of HashSet set ; HashSet (Collection <? extends e> c)
A collection of Java Learning Families 2