ArrayList get all values for an object property
问题 Lets say I have an ArrayList of a object User so ArrayList<user> . A User object has a property userID . Rather than iterating the list myself and adding userIDs to a separate list, is there and API call where I could pass it the property I want on that object and have a list of these properties returned to me? Had a look through the API and nothing stood out. Looking for a solution in Java 7 or <. 回答1: You can do this using lambdas expressions (Java 8) : import java.util.*; import java.util