If I have a list of an example class User (shown below), can I create a String array for all the names in the list with one line using lambda?
class User{
String name;
int id;
}
Yes.
Given List<User> users:
String[] names = users.stream().map(user -> user.name).toArray(String[]::new);
That is "stream the users, get the name for each one, put them in a new String array."
If your User has a getName() method, then it would be:
String[] names = users.stream().map(User::getName).toArray(String[]::new);