1. 程式人生 > >Java學習筆記35:集合的遍歷

Java學習筆記35:集合的遍歷

@SuppressWarnings(“unchecked”)
import java.util.ArrayList;
import java.util.Collection;

public class Demo1_Collection {
//集合的遍歷
public static void main(String[] args) {
@SuppressWarnings(“rawtypes”)
Collection c =new ArrayList();
c.add(new Student(“張三”,23));
c.add(new Student(“李四”,24));
c.add(new Student(“王五”,25));

	Object[] arr =c.toArray();
	for(int i=0; i<arr.length;i++ ){
		Student s=(Student)arr[i];
		System.out.println(s.getName()+"  "+s.getAge());
	}
}

}