Here you can find the source of cast(Stream
public static <T, U> Stream<U> cast(Stream<T> stream, Class<U> type)
//package com.java2s; //License from project: Open Source License import java.util.stream.Stream; public class Main { /**/*from w w w . ja v a 2 s .c om*/ * Cast all elements in a stream to a given type, possibly throwing a * {@link ClassCastException}. * * <pre> * {@code * StreamUtils.cast(Stream.of(1, "a", 2, "b", 3),Integer.class) * // throws ClassCastException * } */ public static <T, U> Stream<U> cast(Stream<T> stream, Class<U> type) { return stream.map(type::cast); } }