import java.util.*;
public class Test {
public static void main(String[] args)throws Exception{
Vector cc=new Vector(); //Vector方法和Stack方法以及之前的ArrayList都大同小异,学会一个其他的就简单了。
Sp sp1=new Sp("001","巧克力",20f);
Sp sp2=new Sp("002","果浦",10f);
cc.add(sp1);
cc.add(sp2);
for(int i=0;i<cc.size();i++){
System.out.println(((Sp)cc.get(i)).getMingcheng());
}
Stack dd=new Stack();
Sp sp1=new Sp("001","巧克力",20f);
Sp sp2=new Sp("002","果浦",10f);
dd.add(sp1);
dd.add(sp2);
for(int i=0;i<dd.size();i++){
System.out.println(((Sp)dd.get(i)).getMingcheng());
}
}
}
class Sp {
private String bianhao;
private String mingcheng;
private float jiage;
Sp(String bianhao,String mingcheng,float jiage){
this.bianhao=bianhao;
this.mingcheng=mingcheng;
this.jiage=jiage;
}
public String getBianhao() {
return bianhao;
}
public void setBianhao(String bianhao) {
this.bianhao = bianhao;
}
public String getMingcheng() {
return mingcheng;
}
public void setMingcheng(String mingcheng) {
this.mingcheng = mingcheng;
}
public float getJiage() {
return jiage;
}
public void setJiage(float jiage) {
this.jiage = jiage;
}
}
JAVA进阶4.8——Vector和Stack
最新推荐文章于 2022-07-30 16:45:53 发布