久久久久久久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>
                          主站蜘蛛池模板: 中文字幕一区二区三区四区 | 欧美日韩久久精品 | 国产一区二区三区久久久久久久久 | 黄网站涩免费蜜桃网站 | 久久久久无码国产精品一区 | 一区二区三区视频 | 91麻豆产精品久久久久久夏晴子 | 午夜精品视频在线观看 | 中文字幕精品一区二区三区精品 | 精品日韩一区 | 日本欧美大片 | 97人人超碰 | 在线免费激情视频 | 国产成人jvid在线播放 | 91精品久久久久久综合五月天 | 欧美一区2区三区4区公司 | 在线色网 | 亚洲久久一区 | 久久久久香蕉视频 | 国产农村妇女毛片精品久久麻豆 | 亚洲日本成人 | 中文在线一区二区 | 一区二区三区观看视频 | 91亚洲一区| 久久综合九色综合欧美狠狠 | 黄色片网此 | 亚洲iv一区二区三区 | 夜夜骚视频 | 欧洲成人免费视频 | 欧美日韩综合视频 | 国产综合一区二区 | 成人欧美一区二区三区在线播放 | av喷水| 中文字幕人成乱码在线观看 | 一区精品视频 | 欧美日韩视频在线 | 午夜影院操| 欧美福利| 亚洲视频 欧美视频 | 久久久一 | 欧美天堂在线 |