Java IntStream asLongStream()

Java IntStream asLongStream()

IntStream asLongStream() 返回一个由这个流的元素组成的 LongStream ,并转换为长字符串。这是一个 中间操作, 中间操作是在一个Stream实例上调用的,在它们完成处理后,会给出一个Stream实例作为输出。

语法:

LongStream asLongStream()

其中,LongStream是一连串的 原始的长值元素。

返回值: IntStream asLongStream()返回一个由该流的元素组成的LongStream,并转换为long。

例子 1 :

// Java code for LongStream asLongStream()
// to return a LongStream consisting of
// the elements of this stream
import java.util.*;
import java.util.stream.IntStream;
import java.util.stream.LongStream;
  
class GFG {
  
    // Driver code
    public static void main(String[] args)
    {
        // Creating an IntStream
        IntStream stream = IntStream.of(3, 5, 9, 12, 14);
  
        // Using LongStream asLongStream()
        LongStream stream1 = stream.asLongStream();
  
        // Displaying LongStream consisting of
        // the elements of this stream
        stream1.forEach(System.out::println);
    }
}

输出:

3
5
9
12
14

例2 :

// Java code for LongStream asLongStream()
// to return a LongStream consisting of
// the elements of this stream
import java.util.*;
import java.util.stream.IntStream;
import java.util.stream.LongStream;
  
class GFG {
  
    // Driver code
    public static void main(String[] args)
    {
        // Creating an IntStream and using asLongStream()
        LongStream stream = IntStream.range(3, 8).asLongStream();
  
        // Displaying LongStream consisting of
        // the elements of this stream
        stream.forEach(System.out::println);
    }
}

输出:

3
4
5
6
7

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程