<small id='8h48X'></small><noframes id='8h48X'>

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

    <tfoot id='8h48X'></tfoot>

    <legend id='8h48X'><style id='8h48X'><dir id='8h48X'><q id='8h48X'></q></dir></style></legend>
    1. Java替换字符串特定位置的字符?

      时间:2023-07-28

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

      <tfoot id='nSu2Z'></tfoot>

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

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

            <bdo id='nSu2Z'></bdo><ul id='nSu2Z'></ul>
                本文介绍了Java替换字符串特定位置的字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我正在尝试替换字符串特定位置的字符.

                I am trying to replace a character at a specific position of a string.

                例如:

                String str = "hi";
                

                将字符串位置 #2 (i) 替换为另一个字母k"

                replace string position #2 (i) to another letter "k"

                我该怎么做?谢谢!

                推荐答案

                Petar Ivanov 对 替换字符串问题中特定索引处的字符

                字符串在 Java 中是不可变的.您无法更改它们.

                String are immutable in Java. You can't change them.

                您需要创建一个替换字符的新字符串.

                You need to create a new string with the character replaced.

                String myName = "domanokz";
                String newName = myName.substring(0,4)+'x'+myName.substring(5);
                

                或者您可以使用 StringBuilder:

                Or you can use a StringBuilder:

                StringBuilder myName = new StringBuilder("domanokz");
                myName.setCharAt(4, 'x');
                
                System.out.println(myName);
                

                这篇关于Java替换字符串特定位置的字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:具有 int 和 char 操作数的三元表达式的类型是什么 下一篇:Java Switch 语句 - 是“或"/“和"可能的?

                相关文章

                最新文章

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

              • <small id='yJIig'></small><noframes id='yJIig'>

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