I want to use Java 8 tricks to do the following in one line.
Given this object definition:
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class MyObj {
private String id;
private Double value;
}
and a List<MyObj> objects
, I want to get a List<String> objectIds
which is a list of all id
s of the objects in the first list - in the same order.
I can do this using a loop in Java but I believe there should be a one-liner lambda in Java8 that can do this. I was not able to find a solution online. Perhaps I wasn't using the right search terms.
Could someone suggest a lambda or another one-liner for this transform?