<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                # Java 流裝箱示例 > 原文: [https://howtodoinjava.com/java8/java8-boxed-intstream/](https://howtodoinjava.com/java8/java8-boxed-intstream/) 在 [Java 8](https://howtodoinjava.com/java-8-tutorial/) 中,如果要將對象流轉換為集合,則可以使用[`Collector`](https://docs.oracle.com/javase/8/docs/api/java/util/stream/Collectors.html)類中的靜態方法之一。 ```java //It works perfect !! List<String> strings = Stream.of("how", "to", "do", "in", "java") .collect(Collectors.toList()); ``` 但是,相同的過程不適用于原始類型流。 ```java //Compilation Error !! IntStream.of(1,2,3,4,5) .collect(Collectors.toList()); ``` 要轉換原始流,必須首先將包裝類中的元素[裝箱](https://docs.oracle.com/javase/8/docs/api/java/util/stream/IntStream.html#boxed--),然后收集它們。 這種類型的流稱為**裝箱流**。 ## 1\. `IntStream` – 整數流 **示例將`int`流轉換為`Integer`列表**。 ```java //Get the collection and later convert to stream to process elements List<Integer> ints = IntStream.of(1,2,3,4,5) .boxed() .collect(Collectors.toList()); System.out.println(ints); //Stream operations directly Optional<Integer> max = IntStream.of(1,2,3,4,5) .boxed() .max(Integer::compareTo); System.out.println(max); ``` 程序輸出: ```java [1, 2, 3, 4, 5] 5 ``` ## 2\. `LongStream` – 長整數流 **示例將`long`流轉換為`Long`列表**。 ```java List<Long> longs = LongStream.of(1l,2l,3l,4l,5l) .boxed() .collect(Collectors.toList()); System.out.println(longs); Output: [1, 2, 3, 4, 5] ``` ## 3\. `DoubleStream` – 雙精度流 **示例將`double`流轉換為`Double`列表**。 ```java List<Double> doubles = DoubleStream.of(1d,2d,3d,4d,5d) .boxed() .collect(Collectors.toList()); System.out.println(doubles); Output: [1.0, 2.0, 3.0, 4.0, 5.0] ``` 在 [Java 流 API](https://howtodoinjava.com/java8/java-streams-by-examples/) 中與**裝箱流**或**原始類型**有關的評論部分中,向我提出您的問題。 學習愉快!
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看