Count number of items with property

后端 未结 10 2542
不思量自难忘°
不思量自难忘° 2021-02-13 12:18

I have list List where Custom is like

class Custom{
    public int id;
    public String name;
}

How to

10条回答
  •  长情又很酷
    2021-02-13 13:04

    Easier probably not. Now you could store your objects in a Map > instead where the key is the name. To get the number of items where name == "Tom" you can then simply do:

    List l = myMap.get("Tom");
    int count = 0;
    if (l != null) {
        count = l.size();
    }
    

提交回复
热议问题