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<String, ArrayList<Person>> map1 = new HashMap<>();
        Map<String, ArrayList<Person>> map2 = new HashMap<>();
        Map<String, ArrayList<Person>> map3 = new HashMap<>();
        ArrayList<Person> 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<Person>());
            }
            map1.get(person.getCid()).add(person);
        }
        Set<String> strings = map1.keySet();
        for (String string : strings) {
            System.out.println(string + map1.get(string));
        }

    }
}

运行结果

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值