Convert Strings to objects in streams
You have a class called Word.
class Word {
private String word;
public Word(String word) {
this.word = word;
}
...
}
You have a list of strings but need to work with Word objects.
List<String> list = Arrays.asList("A", "B", "C");
Create a stream of the list and use the map function:
list.stream().map(item -> new Word(item));
When continuing with this line you have a Stream<Word> instance.
Written by Ivo Limmen
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Lambda
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#