list of collections Collections Framework

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 processHere Insert Picture Description

2.2 foreach loop
Here Insert Picture Description
2.3 iterator Here Insert Picture Description
code to run as a result of
Here Insert Picture Description
additional : remover remover method methods for the collection and iterator What is the difference?
1. First set remover method explained
Here Insert Picture Description
here is a method of collection using a remover in the iterator
Here Insert Picture Description
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
Here Insert Picture Description

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)
Here Insert Picture DescriptionHere Insert Picture Description
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:
Here Insert Picture Description
in FIG write an iterator:
Here Insert Picture Description
results are as follows Here Insert Picture Description
attached by Arratlist provided by an index code from all the foregoing for convenient

Here Insert Picture Description
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:
Here Insert Picture Description
re-write a method outside the main method, as shown below:
Here Insert Picture Description
Run resultHere Insert Picture Description

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
    Here Insert Picture Description
    4.1 stack (last-out)
    Preparation: Write the following main process:
    Here Insert Picture Description
    write method of a Here Insert Picture Description
    4.2 queue (FIFO)
    Preparation: In the main process write the following:
    Here Insert Picture Description
    write a method
    Here Insert Picture Description

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
Here Insert Picture Description

And then define a method, as shown:
Here Insert Picture Description
Run 4 should result

The object is a custom element 5.2
Preparation: Write the following main process
Here Insert Picture Description

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

Guess you like

Origin blog.csdn.net/weixin_44255950/article/details/94591895