久久久久久久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)?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我正在編寫一個小的 JAVA 程序:

                I'm writing a small JAVA program which:

                • 將文本作為字符串
                • 需要 2 個字符數組

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

                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.

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

                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.

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

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

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

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

                最有效的方法是什么?為什么?我想過循環文本,但后來發現效率不高.

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

                這種方式很有效,因為它使用 StringBuilder 來更改字符(如果您使用字符串,則每次都必須創建新的,因為它們是不可變的.)而且它還最大限度地減少了您必須執行的傳遞次數(1 傳遞文本字符串,n 傳遞第一個數組,其中 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())

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

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

                相關文檔推薦

                quot;Char cannot be dereferencedquot; error(“Char 不能被取消引用錯誤)
                Java Switch Statement - Is quot;orquot;/quot;andquot; possible?(Java Switch 語句 - 是“或/“和可能的?)
                Java Replace Character At Specific Position Of String?(Java替換字符串特定位置的字符?)
                What is the type of a ternary expression with int and char operands?(具有 int 和 char 操作數的三元表達式的類型是什么?)
                Read a text file and store every single character occurrence(讀取文本文件并存儲出現的每個字符)
                Why do I need to explicitly cast char primitives on byte and short?(為什么我需要在 byte 和 short 上顯式轉換 char 原語?)
                  <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>
                          主站蜘蛛池模板: 久久久久亚洲 | 久久精品免费 | 中文字幕在线视频免费视频 | 欧美高清性xxxxhdvideosex | 亚洲欧美中文字幕 | 久久免费精品 | 免费观看一级特黄欧美大片 | 97在线观视频免费观看 | 91视在线国内在线播放酒店 | 日韩爱爱网站 | 精品无码三级在线观看视频 | 大乳boobs巨大吃奶挤奶 | 日日综合 | 国产一区二区三区久久久久久久久 | 91视频在线观看免费 | 懂色中文一区二区在线播放 | 亚洲精品视频在线观看免费 | 午夜影院在线视频 | 亚洲 日本 欧美 中文幕 | 一级免费a | 国产一区二区精品在线观看 | 久久久一二三区 | 超碰操 | 日本精品一区二区在线观看 | 成人在线免费 | 欧美一区2区三区4区公司二百 | 亚洲精品一区二区三区蜜桃久 | 亚洲国产欧美一区二区三区久久 | 久久久精品天堂 | 久久精品视频一区二区三区 | 日本不卡免费新一二三区 | 在线成人免费观看 | 日韩欧美一区二区三区免费观看 | 欧美一级欧美三级在线观看 | 亚洲不卡在线观看 | 一区二区国产精品 | 宅女噜噜66国产精品观看免费 | 瑟瑟视频在线看 | 精品免费在线 | 欧美精品在线视频 | 97高清国语自产拍 |