So I've got a list as follows, with the lambda expression:
ArrayList<String> array = new ArrayList<>();
...
StringBuffer buf = new StringBuffer("");
array.stream().forEach((item) -> {
buf.append("Counter here: " + item.toString() + "\n");
});
return buf.toString();
But i can't instantiate and modify a variable within the forEach
lambda expression because it has to be final
. Is there a way i can do this?