1. The frame set (Introduction, Collection method, iterator)
Api provides a document online address http://tool.oschina.net/apidocs/apidoc?api=jdk-zh (direct access, take in bloom).
1. Introduction
The origin of the set of frame: for storing a plurality of data objects, the object with a set of multiple stores. And store data (data structures) are different, the storage container will have more, thereby forming a framework of this collection system
2. traversal set of three kinds (the foreach, the iterator)
Preparation: first is written in the main process
2.2 foreach loop
2.3 iterator
code to run as a result of
additional : remover remover method methods for the collection and iterator What is the difference?
1. First set remover method explained
here is a method of collection using a remover in the iterator
will be run after the problem, a simple explanation is concurrency issues, it.next () means the pointer is moved down in the vessel leading to the emergence of java.util.ConcurrentModificationException
correct wording remover method is used in the iterator iterator
2. The frame set frame collection List (ArrayList specific methods, specific iterator, the object-specific characteristics, demonstrated a growth factor)
1. Personal ArrayList provides a method (and add specific remove)
in which can be seen add (int index, E element) and remover (int index) int type methods are provided with a parameter of this kind can be seen index container is, according to the index can pick up, delete ... like manner to the operating element of the container
2. the specific iterator (list explain specific method listIterator)
preparation: write the code in the main process as follows:
in FIG write an iterator:
results are as follows
attached by Arratlist provided by an index code from all the foregoing for convenient
Must first traverse the front to the back in order to traverse from the back to the front (arraylist traversal of traversal by its nature is an arrow, the arrow at the top very beginning, traversing back through the past, the arrow at the bottom, in the realization from behind by up to facilitate traversing)
3. Specific features of the object, demonstrated growth factor
Features 3.1 specific object
List features three subclasses:
①Arraylist:
an array structure deletions slow query fast continuous subscript threads are not synchronized growth factor for 1.5 10
② the Vector:
an array structure CRUD are slow continuous subscript Thread Synchronization 10 growth factor 2
the Vector relatively slow query ArrayList (thread-safe)
the Vector LinkedList relatively slow additions and deletions (array structure)
③Linkedlist:
linked list structure deletions fast, slow queries no continuous subscript
3.2 Growth Factor demonstration
Preparation: Write the following main processes:
re-write a method outside the main method, as shown below:
Run result
4. The frame set LinkedList
- Container to produce a set of stack structure by linkedList
- Acquiring a production configuration of a container production queue
first set LinkedList appreciated
4.1 stack (last-out)
Preparation: Write the following main process:
write method of a
4.2 queue (FIFO)
Preparation: In the main process write the following:
write a method
The frame set ArrayList repeating elements in its underlying principle to heavy
5.1 element is a string
Preparation: In the main method to write the following code in person
And then define a method, as shown:
Run 4 should result
The object is a custom element 5.2
Preparation: Write the following main process
And then define a method, as in FIG.
class Person{
private String name;
private int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
@Override
public String toString() {
return "Persion [name=" + name + ", age=" + age + "]";
}
public Person(String name, int age) {
super();
this.name = name;
this.age = age;
}
public Person() {
super();
}
public boolean equals(Object obj) {
Person p = (Person) obj;
// System.out.println(p.name+"---equals---"+this.name);
return p.name.equals(this.name) && p.age == this.age;
}
}
After the operation result should be 4