久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    <tfoot id='x7tmK'></tfoot>

  1. <i id='x7tmK'><tr id='x7tmK'><dt id='x7tmK'><q id='x7tmK'><span id='x7tmK'><b id='x7tmK'><form id='x7tmK'><ins id='x7tmK'></ins><ul id='x7tmK'></ul><sub id='x7tmK'></sub></form><legend id='x7tmK'></legend><bdo id='x7tmK'><pre id='x7tmK'><center id='x7tmK'></center></pre></bdo></b><th id='x7tmK'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='x7tmK'><tfoot id='x7tmK'></tfoot><dl id='x7tmK'><fieldset id='x7tmK'></fieldset></dl></div>

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

      <legend id='x7tmK'><style id='x7tmK'><dir id='x7tmK'><q id='x7tmK'></q></dir></style></legend>
    1. <small id='x7tmK'></small><noframes id='x7tmK'>

    2. 替換字符串中的字符的有效方法(java)?

      Efficient way to replace chars in a string (java)?(替換字符串中的字符的有效方法(java)?)
      1. <i id='vPPL5'><tr id='vPPL5'><dt id='vPPL5'><q id='vPPL5'><span id='vPPL5'><b id='vPPL5'><form id='vPPL5'><ins id='vPPL5'></ins><ul id='vPPL5'></ul><sub id='vPPL5'></sub></form><legend id='vPPL5'></legend><bdo id='vPPL5'><pre id='vPPL5'><center id='vPPL5'></center></pre></bdo></b><th id='vPPL5'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='vPPL5'><tfoot id='vPPL5'></tfoot><dl id='vPPL5'><fieldset id='vPPL5'></fieldset></dl></div>
          <legend id='vPPL5'><style id='vPPL5'><dir id='vPPL5'><q id='vPPL5'></q></dir></style></legend>

              <tbody id='vPPL5'></tbody>

            <tfoot id='vPPL5'></tfoot>

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

              1. <small id='vPPL5'></small><noframes id='vPPL5'>

                本文介紹了替換字符串中的字符的有效方法(java)?的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                問題描述

                我正在編寫一個(gè)小的 JAVA 程序:

                I'm writing a small JAVA program which:

                • 將文本作為字符串
                • 需要 2 個(gè)字符數(shù)組

                我嘗試做的事情聽起來像是查找和替換",但它不一樣,所以我認(rèn)為清除它很重要.

                What im trying to do will sound like "find and replace" but it is not the same so i thought its important to clear it.

                無論如何,我想獲取此文本,查找第一個(gè)數(shù)組中的任何字符是否與文本中的字符匹配,如果是,則將其替換為第二個(gè)字符數(shù)組中的匹配字符(根據(jù)索引).

                Anyway I want to take this text, find if any char from the first array match a char in the text and if so, replace it with the matching char (according to index) from the second char array.

                我會(huì)用一個(gè)例子來解釋:假設(shè)我的文本(字符串)是:java 很棒!";我有 2 個(gè)數(shù)組(char[]):absm"和!@*$".

                I'll explain with an example: lets say my text (String) is: "java is awesome!"; i have 2 arrays (char[]): "absm" and "!@*$".

                希望的結(jié)果是將 'a' 更改為 '!', 'b' 到 '@' 等等..意味著結(jié)果文本將是:

                The wished result is to change 'a' to '!' , 'b' to '@' and so on.. meaning the resulted text will be:

                java 太棒了!"改為 -> "j i* @w*o$e!"

                最有效的方法是什么?為什么?我想過循環(huán)文本,但后來發(fā)現(xiàn)效率不高.

                What is the most efficient way of doing this and why? I thought about looping the text, but then i found it not so efficient.

                (StringBuilder/可以使用String類)

                (StringBuilder/String class can be used)

                推薦答案

                StringBuilder sb = new StringBuilder(text);
                    for(int i = 0; i<text.length(); i ++)
                    {
                        for (int j = 0; j < firstCharArray.length;j++)
                        {
                            if (sb.charAt(i) == firstCharArray[j])
                            {
                                sb.setCharAt(i, secondCharArray[j]);
                                break;
                            }
                
                        }
                    }
                

                這種方式很有效,因?yàn)樗褂?StringBuilder 來更改字符(如果您使用字符串,則每次都必須創(chuàng)建新的,因?yàn)樗鼈兪遣豢勺兊?)而且它還最大限度地減少了您必須執(zhí)行的傳遞次數(shù)(1 傳遞文本字符串,n 傳遞第一個(gè)數(shù)組,其中 n = text.length())

                This way is efficient because it uses a StringBuilder to change the characters in place (if you used Strings you would have to create new ones each time because they are immutable.) Also it minimizes the amount of passes you have to do (1 pass through the text string and n passes through the first array where n = text.length())

                這篇關(guān)于替換字符串中的字符的有效方法(java)?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

                相關(guān)文檔推薦

                quot;Char cannot be dereferencedquot; error(“Char 不能被取消引用錯(cuò)誤)
                Java Switch Statement - Is quot;orquot;/quot;andquot; possible?(Java Switch 語(yǔ)句 - 是“或/“和可能的?)
                Java Replace Character At Specific Position Of String?(Java替換字符串特定位置的字符?)
                What is the type of a ternary expression with int and char operands?(具有 int 和 char 操作數(shù)的三元表達(dá)式的類型是什么?)
                Read a text file and store every single character occurrence(讀取文本文件并存儲(chǔ)出現(xiàn)的每個(gè)字符)
                Why do I need to explicitly cast char primitives on byte and short?(為什么我需要在 byte 和 short 上顯式轉(zhuǎn)換 char 原語(yǔ)?)
                  <tbody id='JCp7c'></tbody>
                • <i id='JCp7c'><tr id='JCp7c'><dt id='JCp7c'><q id='JCp7c'><span id='JCp7c'><b id='JCp7c'><form id='JCp7c'><ins id='JCp7c'></ins><ul id='JCp7c'></ul><sub id='JCp7c'></sub></form><legend id='JCp7c'></legend><bdo id='JCp7c'><pre id='JCp7c'><center id='JCp7c'></center></pre></bdo></b><th id='JCp7c'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='JCp7c'><tfoot id='JCp7c'></tfoot><dl id='JCp7c'><fieldset id='JCp7c'></fieldset></dl></div>
                      1. <small id='JCp7c'></small><noframes id='JCp7c'>

                        <legend id='JCp7c'><style id='JCp7c'><dir id='JCp7c'><q id='JCp7c'></q></dir></style></legend>

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

                        • <tfoot id='JCp7c'></tfoot>
                          主站蜘蛛池模板: 国产精品久久久久久久午夜 | 国产精品美女久久久久久久久 | 日本免费在线视频 | 天天搞天天干 | 国产欧美精品一区二区三区 | 久久精品国产一区 | 五月天婷婷影院 | 久久久九九 | 日本伊人网| 日韩av在线一区 | 欧美一级二级三级 | 欧美久久视频 | 99这里只有精品视频 | 激情五月综合色婷婷一区二区 | 一区二区三区国产 | 真实人妻互换毛片视频 | 亚洲精品1区 | 亚洲一区二区三区在线视频 | 免费观看a级片 | 日韩激情一区 | 天天操天天操天天操 | 中国女人真人一级毛片 | 欧美精品二区 | 一区中文字幕 | 麻豆av网站| 日本亚洲欧美 | 九一九色国产 | 天天操夜夜摸 | 深夜福利久久 | 日本不卡视频在线观看 | 精品自拍视频 | 亚洲精品一区二区三区精华液 | www.午夜 | 91在线视频| 国产在线www | 青青草视频污 | 97国产精品| 免费网站观看www在线观 | 成人国产精品视频 | 日韩久久一区 | 在线观看黄网站 |