public class Main {
static class Account {
private Long id;
private String name;
private Book book;
public Account(Long id, String name, Book book) {
this.id = id;
this.name = name;
this.book = book;
}
public String getName() {
return name;
}
}
public static void main(String[] args) {
List<Account> data1 = new ArrayList<>();
data1.add(new Account(1L,"name",null));
List<String> collect = data1.stream().map(account -> account.getName()).collect(Collectors.toList());
System.out.println(collect);
}
}
In the above code I am trying to convert the following line
List<String> collect = data1.stream().map(account -> account.getName()).collect(Collectors.toList());
into kotlin code. Kotlin online editor gives me the following code
val collect = data1.stream().map({ account-> account.getName() }).collect(Collectors.toList())
println(collect)
which gives compilation error when i try to run it.
how to fix this???
or what is the kotlin way to get list of string from list of Account Object