list练习题—输入工人信息

1) 创建一个List,在List 中增加三个工人,基本信息如下:

姓名 年龄 工资 

zhang3 18 3000 

li4 25 3500 

wang5 22 3200 

2) 在li4 之前插入一个工人,信息为:姓名:zhao6,年龄:24,工资3300 

3) 删除wang5 的信息 

4) 利用for 循环遍历,打印List 中所有工人的信息 

5) 利用迭代遍历

package com.Summer_0511.cn;

import java.util.ArrayList;
import java.util.List;

class Employee{
    private String name;
    private int age;
    private double sal;
    public Employee(String name, int age, double sal) {
        super();
        this.name = name;
        this.age = age;
        this.sal = sal;
    }
    @Override
    public String toString() {
        return "Emplyee [name=" + name + ", age=" + age + ", sal=" + sal + "]";
    }
    
}
public class Test07 {

    public static void main(String[] args) {
        Employee zhang3 = new Employee("张三", 22, 2000);
        Employee li4 = new Employee("李四", 33, 3000);
        Employee wang5 = new Employee("王五", 44, 10000);
        List<Employee> list = new ArrayList();
        list.add(zhang3);
        list.add(li4);
        list.add(1, wang5);
        list.remove(wang5);
        for (Employee employee : list) {
            System.out.println(employee);
        }
        System.out.println("--------------");
        list.iterator().forEachRemaining(System.out::println);
    }

}

 

posted @ 2019-05-11 23:29  Geek张东坡  阅读(719)  评论(0编辑  收藏  举报