package 泛型自定义2;
import java.util.ArrayList;
/*
*/
public class FanXingZDY {
public static void main(String[] args) {
Man m1 = new Man("张一","110","抓雷二");
Man m2 = new Man("雷二","120","抓徐三");
Man m3 = new Man("徐三","119","抓铠四");
// ArrayList al = new ArrayList();
// ArrayList al = new ArrayList<String>();
ArrayList al = new ArrayList<Man>();
// 这些都是一样的,
al.add(m1);
al.add(m2);
al.add(m3);
al.add(null);
al.add("王刚");
System.out.println(al);
System.out.println("----------------------------------------");
for (Object ob : al) {
System.out.println(ob);
}
}
}
package 泛型自定义2;
/*
*/
public class Man {
String name;
String ZhanDouLi;
String GankeMuBiao;
public Man() {
super();
// TODO Auto-generated constructor stub
}
public Man(String name, String zhanDouLi, String gankeMuBiao) {
super();
this.name = name;
ZhanDouLi = zhanDouLi;
GankeMuBiao = gankeMuBiao;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the zhanDouLi
*/
public String getZhanDouLi() {
return ZhanDouLi;
}
/**
* @param zhanDouLi the zhanDouLi to set
*/
public void setZhanDouLi(String zhanDouLi) {
ZhanDouLi = zhanDouLi;
}
/**
* @return the gankeMuBiao
*/
public String getGankeMuBiao() {
return GankeMuBiao;
}
/**
* @param gankeMuBiao the gankeMuBiao to set
*/
public void setGankeMuBiao(String gankeMuBiao) {
GankeMuBiao = gankeMuBiao;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return name + ":" + ZhanDouLi + ":"
+ GankeMuBiao ;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
//public String toString() {
// return "Man [name=" + name + ", ZhanDouLi=" + ZhanDouLi + ", GankeMuBiao="
// + GankeMuBiao + "]";
//}
}
|
|