@Data
class Account{
public Account(String accountId, String name){
this.accountId = accountId;
this.name = name;
}
private String accountId;
private String name;
}
public static void main(String[] args) {
List<Account> accounts = new ArrayList<>();
accounts.add("123", "abc");
accounts.add("456", "efg");
// 把AccountId剥离出来。形成一个新的List
List<String> accountIds = accounts.stream().map(Account::getAccountId()).collect(Collectors.toList());
}