IntStream asLongStream()返回包含此流元素的LongStream,並將其轉換為long。這是一個中間操作。在Stream實例上調用中間操作,並在完成處理後將中間實例作為輸出提供。
用法:
LongStream asLongStream() Where, LongStream is a sequence of primitive long-valued element.
返回值: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
相關用法
- Java IntStream sum()用法及代碼示例
- Java IntStream of()用法及代碼示例
- Java IntStream min()用法及代碼示例
- Java IntStream max()用法及代碼示例
- Java IntStream builder()用法及代碼示例
- Java IntStream boxed()用法及代碼示例
- Java IntStream mapToObj()用法及代碼示例
- Java IntStream limit()用法及代碼示例
- Java IntStream mapToDouble()用法及代碼示例
- Java IntStream concat()用法及代碼示例
- Java IntStream skip()用法及代碼示例
- Java IntStream asDoubleStream()用法及代碼示例
- Java IntStream mapToLong()用法及代碼示例
- Java IntStream range()用法及代碼示例
- Java IntStream parallel()用法及代碼示例
注:本文由純淨天空篩選整理自Sahil_Bansall大神的英文原創作品 IntStream asLongStream() in Java。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。