Java Stream Operation filterType(Stream stream, Class type)

Here you can find the source of filterType(Stream stream, Class type)

Description

filter Type

License

Open Source License

Declaration

@SuppressWarnings("unchecked")
    public static <Sub extends Sup, Sup> Stream<Sub> filterType(Stream<Sup> stream, Class<Sub> type) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Collection;

import java.util.stream.Stream;

public class Main {
    @SuppressWarnings("unchecked")
    public static <Sub extends Sup, Sup> Stream<Sub> filterType(Stream<Sup> stream, Class<Sub> type) {
        return (Stream<Sub>) stream.filter(it -> type.isInstance(it));
    }/*from  w  ww  .j  av a 2  s  .c o  m*/

    public static <Sub extends Sup, Sup> Stream<Sub> filterType(Collection<Sup> collection, Class<Sub> type) {
        return filterType(collection.stream(), type);
    }
}

Related

  1. endsWith(Stream stream, Iterable iterable)
  2. enumerationAsStream(Enumeration e)
  3. equals(Stream first, Stream second)
  4. factorStream(long number)
  5. filterInstances(Stream stream, Class clazz)
  6. findLast(Stream s)
  7. findLastOf(Stream stream)
  8. findStreamAmongst(Class clazz, Collection instances)
  9. firstValue(Stream stream)