I have a class like
public class Person {
public Person(String firstName) {...}
public String getFirstname() {...}
// ... some other fields
}
and a list of objects of those class:
List<Person > objList = new ArrayList<>();
objList.add(new Person("Peter"));
objList.add(new Person("James"));
objList.add(new Person("Bart"));
Now I need a comma-separated-list of the firstnames of this object-list, like "Peter,James,Bart"
.
How can I do this using lambdas and streams of Java 8? TIA!