import java . text . DateFormat ; import java . text . SimpleDateFormat ; import java . util . Date ; //员工信息类 //date类 public class test50 { private String name ; private String sex ; private Date birth ; public void showme (){ S
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
//员工信息类
//date类
public class test50 {
private String name;
private String sex;
private Date birth;
public void showme(){
System.out.println(this.getName());
System.out.println(this.getSex());
// System.out.println(DateFormat.getDateInstance().format(this.getBirth()));
//System.out.println(this.getBirth());
SimpleDateFormat sdf=new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
String data=sdf.format(birth);
System.out.println(data);
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setSex(String sex) {
this.sex = sex;
}
public String getSex() {
return sex;
}
public void setBirth(Date birth) {
this.birth = birth;
}
public Date getBirth(Date birth) {
return this.birth;
}
}
测试结果import java.util.Enumeration;
import java.util.Vector;
//verctor
public class test58 {
public static void main(String[] args){
test50 emp0=new test50();
emp0.setName("狼王加内特");
emp0.setSex("男");
test50 emp1=new test50();
emp1.setName("狼王");
emp1.setSex("男");
test50 emp2=new test50();
emp2.setName("加内特");
emp2.setSex("女");
Vector vector=new Vector();
vector.add(emp0);
vector.add(emp1);
vector.add(emp2);
System.out.println("当前元素的是否为空"+vector.isEmpty());
System.out.println("当前元素的元素的个数为"+vector.size());
//获取vector独有的新方法提供元素枚举迭代器
Enumeration enu=vector.elements();
while(enu.hasMoreElements()){
Object obj=enu.nextElement();
test50 temp=(test50)obj;
System.out.println(temp.getName()+"\t"+temp.getSex());
}
if(vector.contains(emp2)){
vector.remove(emp2);
System.out.println("当前元素的元素的个数为"+vector.size());
for(Object obj:vector){
test50 temp=(test50)obj;
System.out.println(temp.getName()+"\t"+temp.getSex());
}
}
}
}
运行结果