1-创建list or link
2-创建学生对象
3-add方法
4-迭代器 or for or superfor
package com.cn1;
import java.sql.SQLOutput;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
public class ListDemo {
public static void main(String[] args) {
//创建一个Arraylist数组
ArrayList<String> arr = new ArrayList<String>();
arr.add("helllo");
arr.add("helllo1");
arr.add("helllo2");
arr.add("helllo3");
//bianli
Iterator<String> it = arr.iterator();
while (it.hasNext()){
String s = it.next();
System.out.println(s);
}
System.out.println("------------");
for(String s : arr){
System.out.println(s);
}
System.out.println("------link------");
LinkedList<String> link = new LinkedList<String>();
link.add("hello");
link.add("java");
link.add("wooo");
Iterator<String> itlink = link.iterator();
System.out.println("-----------");
while (itlink.hasNext()){
String s1 = itlink.next();
System.out.println(s1);
}
for(String s1:link){
System.out.println(s1);
}
ArrayList<Student> list1 = new ArrayList<Student>();
Student s = new Student("ZHANG MANYU",12);
Student s1 = new Student("ZHANG MAN YU",12);
Student s2 = new Student("ZHANG MA NYU",12);
list1.add(s);
list1.add(s1);
list1.add(s2);
for (Student s3:list1){
System.out.println(s3.getAge()+s3.getName());
}
System.out.println("-----------");
for(int i=0;i<list1.size();i++){
Student s4 = list1.get(i);
System.out.println(s4.getAge()+s4.getName());
}
Iterator<Student> it2 = list1.iterator();
while (it2.hasNext()){
Student S = it2.next();
System.out.println(S.getAge()+S.getName());
}
System.out.println("----------------------");
LinkedList <Student> link1 = new LinkedList<Student>();
Student student1 = new Student("ddd",123);
Student student2 = new Student("ddfd",123);
Student student3 = new Student("ddeed",123);
link1.add(student1);
link1.add(student2);
link1.add(student3);
for (Student student5 :link1){
System.out.println(student5.getAge()+student5.getName());
}
}
}