IntStream of() 方法在 Java 中


Java 中的 IntStream of() 方法提供以下兩種形式

IntStream of(int t) 方法

以下 of() 方法返回一個包含一個元素的順序 IntStream。以下是語法

static IntStream of(int t)

在此,引數 t 是唯一元素。

IntStream of(int… values) 方法

以下 of() 方法返回一個順序排列的流,其元素是指定的值

static IntStream of(int… values)

在此,引數 values 是新流的元素。

以下是一個在 Java 中實現 IntStream of() 方法的示例

示例

 即時演示

import java.util.*;
import java.util.stream.IntStream;
public class Demo {
   public static void main(String[] args) {
      IntStream intStream = IntStream.of(10, 20, 30, 40, 50);
      intStream.forEach(System.out::println);
   }
}

輸出

10
20
30
40
50

更新於: 2019 年 7 月 30 日

405 次檢視

開啟你的 職業生涯

完成課程獲取認證

開始
廣告