Filter twice

Description

The following code shows how to filter twice.

Example


import java.util.Arrays;
import java.util.List;
import java.util.Objects;
//w  w w.j a  va2 s.  c  o  m
public class Main {

  public static void main(String[] args)  {
    List<String> liste = Arrays.asList("XML", "HTML", "CSS", null);

    liste.parallelStream()// Parallel stuff uses Fork-Join
            .filter(e -> (!Objects.equals(e, null))) // lazy & parallel
            .filter(e -> (e.length() > 3)) // lazy & parallel
            .forEach(e -> {   // sequential & eagerly
                System.out.println("Bigger length than 3 in List: " + e);
            });

  }
}

The code above generates the following result.





















Home »
  Java Streams »
    Examples »




Average
Filter
Group
IntStream
Map
Partition
Reduce
Sort
Sum