Join a list of object’s properties into a String

To retrieve a String consisting of all the ID’s separated by the delimiter "," you first have to map the Person ID’s into a new stream which you can then apply Collectors.joining on.

String result = personList.stream().map(Person::getId)
                          .collect(Collectors.joining(","));

if your ID field is not a String but rather an int or some other primitive numeric type then you should use the solution below:

String result = personList.stream().map(p -> String.valueOf(p.getId()))
                          .collect(Collectors.joining(","));

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)