Get list of attributes of an object in an List

前端 未结 8 1716
青春惊慌失措
青春惊慌失措 2020-12-12 19:12

When there is an List, is there a possibility of getting List of all person.getName() out of that? Is there an prepared call for that

相关标签:
8条回答
  • 2020-12-12 19:42

    Try this

    Collection<String> names = CollectionUtils.collect(personList, TransformerUtils.invokerTransformer("getName"));  
    

    Use apache commons collection api.

    0 讨论(0)
  • 2020-12-12 19:45

    take a look at http://code.google.com/p/lambdaj/ - there is LINQ equivalent for Java. Using it won't avoid iterating all over items but the code would be more compressed.

    0 讨论(0)
提交回复
热议问题