• <bdo id='35UcN'></bdo><ul id='35UcN'></ul>

  • <tfoot id='35UcN'></tfoot>

    <small id='35UcN'></small><noframes id='35UcN'>

      <legend id='35UcN'><style id='35UcN'><dir id='35UcN'><q id='35UcN'></q></dir></style></legend>

      <i id='35UcN'><tr id='35UcN'><dt id='35UcN'><q id='35UcN'><span id='35UcN'><b id='35UcN'><form id='35UcN'><ins id='35UcN'></ins><ul id='35UcN'></ul><sub id='35UcN'></sub></form><legend id='35UcN'></legend><bdo id='35UcN'><pre id='35UcN'><center id='35UcN'></center></pre></bdo></b><th id='35UcN'></th></span></q></dt></tr></i><div id='35UcN'><tfoot id='35UcN'></tfoot><dl id='35UcN'><fieldset id='35UcN'></fieldset></dl></div>

        Java8:哈希映射&lt;X,Y&gt;到HashMap&lt;X,

        时间:2023-09-26
        <i id='7iI3Q'><tr id='7iI3Q'><dt id='7iI3Q'><q id='7iI3Q'><span id='7iI3Q'><b id='7iI3Q'><form id='7iI3Q'><ins id='7iI3Q'></ins><ul id='7iI3Q'></ul><sub id='7iI3Q'></sub></form><legend id='7iI3Q'></legend><bdo id='7iI3Q'><pre id='7iI3Q'><center id='7iI3Q'></center></pre></bdo></b><th id='7iI3Q'></th></span></q></dt></tr></i><div id='7iI3Q'><tfoot id='7iI3Q'></tfoot><dl id='7iI3Q'><fieldset id='7iI3Q'></fieldset></dl></div>
          <tbody id='7iI3Q'></tbody>

            <bdo id='7iI3Q'></bdo><ul id='7iI3Q'></ul>
            • <tfoot id='7iI3Q'></tfoot>

              <legend id='7iI3Q'><style id='7iI3Q'><dir id='7iI3Q'><q id='7iI3Q'></q></dir></style></legend>
              • <small id='7iI3Q'></small><noframes id='7iI3Q'>

                  本文介绍了Java8:哈希映射&lt;X,Y&gt;到HashMap&lt;X,Z&gt;使用 Stream/Map-Reduce/Collector的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我知道如何转变";Y 的简单 Java List ->Z,即:

                  I know how to "transform" a simple Java List from Y -> Z, i.e.:

                  List<String> x;
                  List<Integer> y = x.stream()
                          .map(s -> Integer.parseInt(s))
                          .collect(Collectors.toList());
                  

                  现在我想对地图做基本相同的事情,即:

                  Now I'd like to do basically the same with a Map, i.e.:

                  INPUT:
                  {
                    "key1" -> "41",    // "41" and "42"
                    "key2" -> "42"      // are Strings
                  }
                  
                  OUTPUT:
                  {
                    "key1" -> 41,      // 41 and 42
                    "key2" -> 42       // are Integers
                  }
                  

                  解决方案不应仅限于String ->整数.就像上面的 List 示例一样,我想调用任何方法(或构造函数).

                  The solution should not be limited to String -> Integer. Just like in the List example above, I'd like to call any method (or constructor).

                  推荐答案

                  Map<String, String> x;
                  Map<String, Integer> y =
                      x.entrySet().stream()
                          .collect(Collectors.toMap(
                              e -> e.getKey(),
                              e -> Integer.parseInt(e.getValue())
                          ));
                  

                  它不如列表代码那么好.您不能在 map() 调用中构造新的 Map.Entry,因此工作会混入 collect() 调用中.

                  It's not quite as nice as the list code. You can't construct new Map.Entrys in a map() call so the work is mixed into the collect() call.

                  这篇关于Java8:哈希映射&lt;X,Y&gt;到HashMap&lt;X,Z&gt;使用 Stream/Map-Reduce/Collector的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:系统覆盖android 4.0 下一篇:在 Hadoop 中更改文件拆分大小

                  相关文章

                  最新文章

                  <legend id='l5DqJ'><style id='l5DqJ'><dir id='l5DqJ'><q id='l5DqJ'></q></dir></style></legend>
                1. <tfoot id='l5DqJ'></tfoot>

                      • <bdo id='l5DqJ'></bdo><ul id='l5DqJ'></ul>

                      <small id='l5DqJ'></small><noframes id='l5DqJ'>

                      <i id='l5DqJ'><tr id='l5DqJ'><dt id='l5DqJ'><q id='l5DqJ'><span id='l5DqJ'><b id='l5DqJ'><form id='l5DqJ'><ins id='l5DqJ'></ins><ul id='l5DqJ'></ul><sub id='l5DqJ'></sub></form><legend id='l5DqJ'></legend><bdo id='l5DqJ'><pre id='l5DqJ'><center id='l5DqJ'></center></pre></bdo></b><th id='l5DqJ'></th></span></q></dt></tr></i><div id='l5DqJ'><tfoot id='l5DqJ'></tfoot><dl id='l5DqJ'><fieldset id='l5DqJ'></fieldset></dl></div>