集合框架(Collection存储字符串和自定义对象遍历)
1 package Day15; 2 3 public class Student3 { 4 private String name; 5 private int age; 6 7 //构造方法 8 public Student3(){ 9 super(); 10 } 11 public Student3(String name,int age){ 12 super(); 13 this.name =name; 14 this.age =age; 15 } 16 17 //setXxx和getXxx方法 18 19 public void setName(String name) { 20 this.name = name; 21 } 22 23 public void setAge(int age) { 24 this.age = age; 25 } 26 27 public String getName() { 28 return name; 29 } 30 31 public int getAge() { 32 return age; 33 } 34 35 //进行对toString方法的重写---方便直接调用对象时输出 36 37 @Override 38 public String toString() { 39 return "Student3{" + 40 "name="" + name + """ + 41 ", age=" + age + 42 "}"; 43 } 44 45 }