zoukankan      html  css  js  c++  java
  • 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);
        }
    
    }
  • 相关阅读:
    含有tuple的list按照tuple中的某一位进行排序
    python
    Python代码追踪(类似于bash -x的效果)
    cinder swift的区别
    C#中Main函数为什么要static
    C#编程.函数.委托
    C#编程.函数.Main()函数
    C#编程.函数.参数
    typedef int a[10];怎么解释?
    C#的DateTime得到特定日期
  • 原文地址:https://www.cnblogs.com/summerdata/p/10850597.html
Copyright © 2011-2022 走看看