Quantcast
Channel: Java 8 modify stream elements - Stack Overflow
Browsing latest articles
Browse All 7 View Live

Answer by Nicolas for Java 8 modify stream elements

If you use Lombok, you can use immutable setters..map(s -> s.withText(s.getText() +"..."))See: https://projectlombok.org/features/With

View Article



Answer by Alex for Java 8 modify stream elements

I think a cleaner and more readable solution is:List<SampleDTO> unmodifiable = Arrays.asList(new SampleDTO("1"), new SampleDTO("2"));List<SampleDTO> modified = unmodifiable.stream() .map(s...

View Article

Answer by Rodney P. Barbati for Java 8 modify stream elements

I think it would be better, especially if doing multi-threaded work, to stream the original list into a new modified list or whatever else is desired.The new list or map or whatever other structure you...

View Article

Answer by Theresa Forster for Java 8 modify stream elements

Streams are immutable like strings so you cannot get around needing to create a new stream/list/array That being said you can use .Collect() to return a new collection post change so...

View Article

Answer by soorapadman for Java 8 modify stream elements

To make this more elegant way I would suggest create a Method with in the class. public class SampleDTO { private String text;public String getText() { return text;}public void setText(String text) {...

View Article


Answer by Eran for Java 8 modify stream elements

You must have some method/constructor that generates a copy of an existing SampleDTO instance, such as a copy constructor. Then you can map each original SampleDTO instance to a new SampleDTO instance,...

View Article

Java 8 modify stream elements

I wanted to write pure function with Java 8 that would take a collection as an argument, apply some change to every object of that collection and return a new collection after the update. I want to...

View Article
Browsing latest articles
Browse All 7 View Live




Latest Images