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

后端 未结 12 1210
长发绾君心
长发绾君心 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 08:54

    try this:

    List entities = getEntities();
    List listIntegerEntities = Lambda.extract(entities, Lambda.on(Entity.class).getFielf1());
    

    the LambdaJ allows to access collections without explicit loops, so instead of have more lines of code to iterate the list yourself, you let LambdaJ do it.

提交回复
热议问题