I am using java 8 stream features now i want to store string value in local variable,but its showing local variables referenced from a lambda expression must be final or effectively final.I also tried final keyword its getting same.I need clarification its possible or not.
public static void main(String[] args) {
List list = Arrays.asList("java", "stream", "scala");
String data = "";
list.forEach(action -> {
data = action.toString();
System.out.println("data :" + data);
});
}
dataoutside lambda? it seems you can remove the variabledatawith each element of the List, so it would have the last element in the end. Do you wish to concatenate all theseStrings? If you do, there are other ways to achieve this.dataoutside lambda