
第一种方法:
定义Employee类,定义id、姓名、薪水等私有属性。

提供构造方法

提供get set 方法

时间传值时,传的是字符串,但是需要的是时间对象,所以在构造方法的时候,直接传字符串。然后在构造方法里格式化。
故构造器修改为

捕捉异常后变为

初始化时传值,类结构对应表结构。


最后定义方法printEmpName,循环遍历容易里所有对象的name

第二种方法:
一个map封装一组数据,一个key对应一个value

然后把map1、map2、map3丢进容器

最后遍历输出name对应的值

注:
Listlist = new ArrayList();
Listlist = new ArrayList();
加入泛型,使得这个容器更加规范
网友评论