栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

2021-10-11

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

2021-10-11

 

public class Person {
    String gid;
    String cid;
    String name;
    String number;
    String gz;
    String gl;//构造参数;

    public Person(String gid, String cid, String name, String number, String gz, String gl) {
        this.gid = gid;
        this.cid = cid;
        this.name = name;
        this.number = number;
        this.gz = gz;
        this.gl = gl;
    }

    public String getGid() {
        return gid;
    }

    public void setGid(String gid) {
        this.gid = gid;
    }

    public String getCid() {
        return cid;
    }

    public void setCid(String cid) {
        this.cid = cid;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getNumber() {
        return number;
    }

    public void setNumber(String number) {
        this.number = number;
    }

    public String getGz() {
        return gz;
    }

    public void setGz(String gz) {
        this.gz = gz;
    }

    public String getGl() {
        return gl;
    }

    @Override
    public String toString() {
        return "Person{" +
                "gid='" + gid + ''' +
                ", cid='" + cid + ''' +
                ", name='" + name + ''' +
                ", number='" + number + ''' +
                ", gz='" + gz + ''' +
                ", gl='" + gl + ''' +
                '}';//qu
    }

    public void setGl(String gl) {
        this.gl = gl;
    }
}
import java.util.*;

public class Demo01 {
    public static void main(String[] args) {

        show01();

    }

    private static void show01() {
        Map> map1 = new HashMap<>();
        Map> map2 = new HashMap<>();
        Map> map3 = new HashMap<>();
        ArrayList arr = new ArrayList<>();
            Collections.addAll(arr, new Person("W1", "WS1", "Chisel", "13024390423", "special", "5"),
                new Person("W2", "WS1", "Asa", null, "expert", null),
                new Person("W3", "WS1", "Parker", "15754183291", "common", "1"),
                new Person("W4", "WS1", "Ron", "18283957359", "common", "0"),
                new Person("W5", "WS1", "Tyler", null, "common", "0"),
                new Person("W6", "WS1", "Tony", "17683934639", " common", "    0"),
                new Person("W7", "WS1", "August", null, "common", "0"),
                new Person("W8", "WS2", "Sam", "13186396347", "special", "5"));
        for (Person person : arr) {      //遍历数组
            if (map1.get(person.getCid()) == null) {
                map1.put(person.getCid(), new ArrayList());
            }
            map1.get(person.getCid()).add(person);
        }
        Set strings = map1.keySet();
        for (String string : strings) {
            System.out.println(string + map1.get(string));
        }

    }
}

运行结果

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/315635.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号