How to get a list of specific fields values from objects stored in a list?

后端 未结 12 1058
长发绾君心
长发绾君心 2021-01-31 08:23

Say I have an list of objects with two fields field1 and field2, both of String type.

How do I get a list of all field1 values wit

12条回答
  •  一向
    一向 (楼主)
    2021-01-31 09:10

    Maybe you could create an hashmap in this way:

    HashMap> map;
    

    The key would be the field. Doing this way, when you ask the HashMap to retrieve you the object corresponding to the field that you want, the map would return you an ArrayList cointaing all of the elements which has that field.

提交回复
热议问题