<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>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                ### 3.3.1 flatMap的用法 通過`map`操作,可以**改變流中元素的類型**,以下代碼將String流映射成了Integer流: ```java List<String> strList = Arrays.asList("stream", "map", "flatMap"); /* 將字符串列表轉成長度列表 */ List<Integer> hashCodeList = strList.stream() .map(String::length) .collect(Collectors.toList()); System.out.println(hashCodeList); ``` 這里可以將其優化為輸出int流,以避免裝箱的性能損耗: ```java /* 性能優化點,避免裝箱 */ int[] hashCodeArr = strList.stream() .mapToInt(String::length) .toArray(); System.out.println(Arrays.toString(hashCodeArr)); ``` ---- `flatMap`的效果是**映射成流的內容**,下面的代碼中,需要選出所有的字符并去重。 `map`操作返回的是`String[]`流,可以通過`flatMap`操作轉成String流,得到最終結果: ```java /* 選出所有的字符,并去重 */ List<String[]> contextStrList = strList.stream() .map(str -> str.split("")) .distinct() .collect(Collectors.toList()); System.out.println(Arrays.deepToString(contextStrList.toArray())); /* 只使用map達不到效果 [[s, t, r, e, a, m], [m, a, p], [f, l, a, t, M, a, p]] */ List<String> contextList = strList.stream() .map(str -> str.split("")) .flatMap(strArr -> Arrays.stream(strArr)) .distinct() .collect(Collectors.toList()); System.out.println(Arrays.deepToString(contextList.toArray())); /* flatMap的效果是映射成流的內容 [s, t, r, e, a, m, p, f, l, M] */ ```
                  <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>

                              哎呀哎呀视频在线观看