Create Stream from String array - Java Lambda Stream

Java examples for Lambda Stream:Stream

Description

Create Stream from String array

Demo Code


import java.util.stream.Stream;

public class Main {

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

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

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

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

Related Tutorials