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

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

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

    2. <tfoot id='UmGky'></tfoot>

          <bdo id='UmGky'></bdo><ul id='UmGky'></ul>

        从代码点编号的 IntStream 中创建一个字符串?

        时间:2023-07-27

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

          <tbody id='vmDny'></tbody>

          <tfoot id='vmDny'></tfoot>
            <bdo id='vmDny'></bdo><ul id='vmDny'></ul>
                  <legend id='vmDny'><style id='vmDny'><dir id='vmDny'><q id='vmDny'></q></dir></style></legend>

                1. <i id='vmDny'><tr id='vmDny'><dt id='vmDny'><q id='vmDny'><span id='vmDny'><b id='vmDny'><form id='vmDny'><ins id='vmDny'></ins><ul id='vmDny'></ul><sub id='vmDny'></sub></form><legend id='vmDny'></legend><bdo id='vmDny'><pre id='vmDny'><center id='vmDny'></center></pre></bdo></b><th id='vmDny'></th></span></q></dt></tr></i><div id='vmDny'><tfoot id='vmDny'></tfoot><dl id='vmDny'><fieldset id='vmDny'></fieldset></dl></div>
                2. 本文介绍了从代码点编号的 IntStream 中创建一个字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  如果我正在使用 Java 流,并以 IntStream of Unicode 字符的>code point 数字,如何呈现 CharSequence 比如 String?

                  If I am working with Java streams, and end up with an IntStream of code point numbers for Unicode characters, how can I render a CharSequence such as a String?

                  String output = "input_goes_here".codePoints(). ??? ;  
                  

                  我在几个接口上找到了一个 codePoints() 方法 &所有生成代码点的 IntStream 的类.但是我还没有找到任何可以接受相同的构造函数或工厂方法.

                  I have found a codePoints() method on several interfaces & classes that all generate an IntStream of code points. Yet I have not been able to find any constructor or factory method that accepts the same.

                  • CharSequence::codePoints() → IntStream
                  • String::codePoints() → IntStream
                  • StringBuilder::codePoints() → IntStream

                  我正在寻找相反的:

                  ➥ 如何从 IntStream 的代码点实例化 StringCharSequence 等?

                  ➥ How to instantiate a String or CharSequence or such from an IntStream of code points?

                  推荐答案

                  使用IntStream::collect 带有 StringBuilder.

                  String output = 
                      "input_goes_here"
                      .codePoints()                            // Generates an `IntStream` of Unicode code points, one `Integer` for each character in the string.
                      .collect(                                // Collect the results of processing each code point.
                          StringBuilder::new,                  // Supplier<R> supplier
                          StringBuilder::appendCodePoint,      // ObjIntConsumer<R> accumulator
                          StringBuilder::append                // BiConsumer<R,​R> combiner
                      )                                        
                      .toString()
                  ;
                  

                  如果您喜欢更通用的 CharSequence 接口在具体 String,只需将 toString() 放在末尾即可.返回的 StringBuilder 是一个 CharSequence.

                  If you prefer the more general CharSequence interface over concrete String, simply drop the toString() at the end. The returned StringBuilder is a CharSequence.

                  IntStream codePointStream = "input_goes_here".codePoints ();
                  CharSequence output = codePointStream.collect ( StringBuilder :: new , StringBuilder :: appendCodePoint , StringBuilder :: append );
                  

                  这篇关于从代码点编号的 IntStream 中创建一个字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:为什么在 Java 中允许将 double 转换为 char? 下一篇:如何在 Java 中将整数添加到 char 中?

                  相关文章

                  最新文章

                    1. <legend id='Ut0gu'><style id='Ut0gu'><dir id='Ut0gu'><q id='Ut0gu'></q></dir></style></legend>
                      <i id='Ut0gu'><tr id='Ut0gu'><dt id='Ut0gu'><q id='Ut0gu'><span id='Ut0gu'><b id='Ut0gu'><form id='Ut0gu'><ins id='Ut0gu'></ins><ul id='Ut0gu'></ul><sub id='Ut0gu'></sub></form><legend id='Ut0gu'></legend><bdo id='Ut0gu'><pre id='Ut0gu'><center id='Ut0gu'></center></pre></bdo></b><th id='Ut0gu'></th></span></q></dt></tr></i><div id='Ut0gu'><tfoot id='Ut0gu'></tfoot><dl id='Ut0gu'><fieldset id='Ut0gu'></fieldset></dl></div>
                      • <bdo id='Ut0gu'></bdo><ul id='Ut0gu'></ul>
                      <tfoot id='Ut0gu'></tfoot>
                    2. <small id='Ut0gu'></small><noframes id='Ut0gu'>