I'm trying to use a lambda expression in a forEach loop to concatenate to a variable "i" a string that is evaluated for each object.
here is the code
private String getStringActiveRooms(@NotNull ArrayList<Chat_room> c){
String i;
c.forEach( (chat_room) -> i = i.concat(chat_room.getName() + "[" + chat_room.activeUsers() + "/" + chat_room.maxUsers() + "]" + ", "));
return i;
}
It throws me an error because external variables must be final to be used in a lambda expression.
But if I make final the variable I can't change it and the code didn't work.
Does anyone have a solution?