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

后端 未结 12 1228
长发绾君心
长发绾君心 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:09

    An object is a reference towards a memory address. Then, the fields of this objects are other references towards other memory addresses. Hence, a list of objects is a list of references. So, it's impossible for the list to direclty access the object fields (references given by the references). The short answer is no.

    Note: anyway you'll find an API that does what you want, it still loops in the inside.

提交回复
热议问题