Collection case
Store strings and Traverse
Store custom objects and traverse
Student (Name,age)
import java.util.Collection;import java.util.Iterator;/* * Requirements: Store strings and traverse them. * * Analysis: * a: Creating a Collection Object * b: Creating a String Object * c: Adding a String object to the collection * d: Iterating through the collection */public class collectiontest { public static void main (String[] args) { // Create collection Objects Collection c = new arraylist (); // Creating a String Object // adding a String object to the collection c.add ("Brigitte"), c.add ("Wind"), c.add ("Elina"), c.add ("Wu Xin"); C.add ("Lynn Qu"); // iterate through the collection // get the iterator object through the collection object iterator it = c.iterator (); // the Hasnext () method of the Iterator object to determine if there is no element while (It.hasnext ()) { // get elements String s = (String) through the next () method of an Iterator object It.next (); system.out. println (s); } }}
The console output in MyEclipse is as follows:
Brigitte
Wind
Elina
Lynn Qu
Do you understand me?
650) this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0013.gif "alt=" J_0013.gif "/>
This article from "GD" blog, reproduced please contact the author!
Collection Framework (collection store strings and traverse)