Wednesday, 26 July 2017

How to filter the names whose length is greater than 4 using Java 8 streams | Streams in Java 8

Click here to watch in Youtube :
import java.util.Arrays;

 * If you have an array of strings, and you want to create a subset of
 * it which contains only those strings whose length is more than four
 * characters,then use below program.
 * How to filter the names whose length is greater than 4?
public class StreamDemo
    public static void main(String[] args)
        String[] nameArray = new String[] { "Peter", "Steve", "paul","Ram" };

        Stream<String> stream =;

         * The filter method expects a lambda expression as its
         * argument. However, the lambda expression passed to it must
         * always return a boolean value, which determines whether or
         * not the processed element should belong to the resulting
         * Stream object.
        Stream<String> filteredStream = stream.filter(name -> name.length() > 4);

        String[] filteredNameArray = filteredStream.toArray(String[]::new);

        for (String name : filteredNameArray)


Click the below link to download the code:

Github Link:

Bitbucket Link:

See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Kids Tutorial

    1. A easy and exciting blog about java learning. Please comment your opinions and share..

    2. Interesting blog which attracted me more.Spend a worthful time.keep updating more.
      Informatica Training in Chennai


    Google+ Followers

    Google+ Badge