1.List接口
1)Student.java (主要的是List接口当中需要使用)
package lx.com.entity;
public class Student {
private String number;
private String name;
/**
*
*/
public Student() {
super();
// TODO Auto-generated constructor stub
}
/**
* @param number
* @param name
*/
public Student(String number, String name) {
this.number = number;
this.name = name;
}
/**
* @return the number
*/
public String getNumber() {
return number;
}
/**
* @param number the number to set
*/
public void setNumber(String number) {
this.number = number;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
}
2)List_test
package lx.com.entity;
import java.util.*;
public class List_test {
public static void main(String[] args) {
// TODO Auto-generated method stub
List list1 = new ArrayList();
list1.add("hello");
list1.add("world");
System.out.println(list1);
Student stu1 = new Student("001","翠花");
Student stu2 = new Student("002","川普");
Student stu3 = new Student("003","碧落");
List<Student> list2 = new ArrayList();
list2.add(stu1);
list2.add(stu2);
list2.add(stu3);
System.out.println(list2);
}
}
?通过list1方式打印的是值,通过list2方式打印的是地址。
2.Map接口
package lx.com.entity;
import java.util.*;
public class Map_test {
public static void main(String[] args) {
// TODO Auto-generated method stub
//以键值对的形式输出,其中是乱序(集合)
Map m1 = new HashMap();
m1.put("碧落", "1");
m1.put("川普", "2");
m1.put("翠花","3");
m1.put("大郎", "4");
System.out.println(m1);
}
}
?
|