Using the Java 8 lambda expression, I am trying to do something like this.
List<NewObject> objs = ...; for (OldObject oldObj : oldObjects) { NewObject obj = oldObj.toNewObject(); obj.setOrange(true); objs.add(obj); }
I wrote this code.
oldObjects.stream() .map(old -> old.toNewObject()) .forEach({new.setOrange("true")}) .collect(Collectors.toList());
This code is incorrect because I am trying to do .collect() to return .forEach() , but forEach invalid and does not return a list.
How should this be structured?
java lambda java-8 java-stream
Jeremy Nov 06 '15 at 12:14 2015-11-06 00:14
source share