Create Stream from Array and do forEach action - Java Lambda Stream

Java examples for Lambda Stream:Stream

Description

Create Stream from Array and do forEach action

Demo Code



import java.util.stream.Stream;


public class BlogMain {

  private final String[] BLOG_ENTRIES = {"First Note", "Another Note", "End"};

  public static void main(String[] args) {
    System.out.println("Blog up and running");
    new BlogMain().printAllNotes();
  }/*w w  w.j  ava 2  s  . co m*/

  public void printAllNotes() {
    Stream.of(BLOG_ENTRIES).forEach(note -> System.out.println(addNote(note)));
  }

  public String addNote(String note) {
    return note.contains("Note") ? note : note + " Note";
  }

}

Related Tutorials