[JAVA] Iterator memo

I will leave a simple usage of Iterator. I haven't touched on Iterator until now, but it seems to be frequent, so I decided to summarize the basic usage.


//List initialization
List<String> list = new ArrayList<>(Arrays.asList("apple","banana","orange","fish"));

//Declaration of Iterator
Iterator<String> iterator = list.iterator();

//Iterator method hasNext()Loop processing using
//hasNext(): Returns true if there are more elements in the iteration.
while(iterator.hasNext()) {
	//Iterator method next()Take out the element with
	//next(): Returns the next element in iterative processing.
	String str = iterator.next();

	if(str.equals("banana")) {
	//Iterator method remove()Delete the element with
	//Removes the last element returned by this iterator from the base collection
[apple, orange, fish]

Recommended Posts

Iterator memo
Integer memo
docker memo
Iterator pattern
Lombok memo
Dockerfile memo
Iterator Pattern
corretto memo
Java memo
AWS memo
Dcokerfile memo
Ruby memo
Memo Stream
Spring retrospective memo
docker tutorial (memo)
java anything memo
primary key memo
Stream API memo
Docker operation memo
Eclipse trick memo
Java Silver memo
JavaParser usage memo
Docker command memo
SpringBoot-JPA-Hibernate addictive memo
Design pattern ~ Iterator ~
Kubernetes/container-related standardization memo
Java SE 7 memo
[Memo] docker summary
OpenJDK 11 installation memo
MySQL migration memo (1)
WatchService usage memo
PlantUML usage memo
java anything memo 2
Docker-compose command memo
e-Gov setting memo
[wip] Ruby memo
Maven3 error memo
Java specification memo
JUnit5 usage memo
Java pattern memo