Two implementation methods for ArrayList iteration in java
- 2020-10-23 20:59:18
- OfStack
Two implementation methods for ArrayList iteration in java
Iterator and for statement combination to achieve, the code is very simple, you refer to the following.
Implementation code:
package cn.us;
import java.util.ArrayList;
import java.util.Iterator;
//ArrayList There are two ways to iterate
//Iterator with for Combination of statements
public class Test1 {
public static void main(String[] args) {
ArrayList arrayList = new ArrayList();
arrayList.add("b");
arrayList.add("z");
arrayList.add("f");
arrayList.add("m");
System.out.println(" The following is a ArrayList The iteration of the first 1 Methods......................................................................................................... ");
Iterator ite=arrayList.iterator();
while(ite.hasNext()){
System.out.println(ite.next());
}
System.out.println(" The following is a ArrayList The iteration of the first 2 Methods......................................................................................................... ");
for (Iterator iterator = arrayList.iterator(); iterator.hasNext();) {
System.out.println(iterator.next());
}
}
}
The above is the method of ArrayList iteration in java. If you have any questions, please leave a message or go to the community of this site to exchange and discuss. Thank you for reading.