Java Stream Operation cast(Stream stream, Class type)

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

Description

Cast all elements in a stream to a given type, possibly throwing a ClassCastException .

License

Open Source License

Declaration

public static <T, U> Stream<U> cast(Stream<T> stream, Class<U> type) 

Method Source Code

//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);
    }
}

Related

  1. arrayWrap(final Stream stream)
  2. asList(Stream stream)
  3. buildInvalidArgsError(Stream values, Stream types)
  4. bytesToIntStream(byte[] bytes)
  5. cat(Stream... streams)
  6. characterStream2(String s)
  7. commaSeparated(Stream stream)
  8. concat(IntStream... streams)

  9. HOME | Copyright © www.java2s.com 2016