I want to use Java 8 tricks to do the following in one line.
Given this object definition:
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
pub
This should do the trick:
objects.stream().map(MyObj::getId).collect(Collectors.toList());
that said, the method reference ::
operator allows you to reference any method in your classpath and use it as a lambda for the operation that you need.
As mentioned in the comments, a stream preserves order.