Several circular accesses to the collection object list in Java are summarized as follows
1 Classic for loop
public static void Main (string[] args) {
list<string> List = new ArrayList ();
List.add ("123");
List.add ("Java");
List.add ("Java ee");
System.out.println ("========= Classic for Loop =======");
for (int i=0; i<list.size (); i++) {
System.out.println (List.get (i));
}
2 Enhanced for loop
public static void Main (string[] args) {
list<string> List = new ArrayList ();
List.add ("123");
List.add ("Java");
List.add ("Java ee");
System.out.println ("=========java1.6 for Loop =======");
for (String s:list) {
System.out.println (s);
}
}
3 Use of Iterate
public static void Main (string[] args) {
list<string> List = new ArrayList ();
List.add ("123");
List.add ("Java");
List.add ("Java ee");
System.out.println ("=========iterate cycle =======");
Iterator<string> iter = List.iterator ();
while (Iter.hasnext ()) {
System.out.println (Iter.next ());
}
}
The above article on the collection object list in Java Several circular access is a small series to share all the content of everyone, hope to give you a reference, but also hope that we support the cloud-dwelling community.