user1343585 user1343585 - 1 year ago 148
Java Question

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

Say I have an list of objects with two fields

, both of String type.

How do I get a list of all
values without having to iterate over the list, if it is at all possible?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download