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

        <bdo id='5lHhO'></bdo><ul id='5lHhO'></ul>
        <legend id='5lHhO'><style id='5lHhO'><dir id='5lHhO'><q id='5lHhO'></q></dir></style></legend>
      1. <tfoot id='5lHhO'></tfoot>
      2. <small id='5lHhO'></small><noframes id='5lHhO'>

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

        Java:帶有char數(shù)組的println給出亂碼

        Java: println with char array gives gibberish(Java:帶有char數(shù)組的println給出亂碼)

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

          <bdo id='gYMDO'></bdo><ul id='gYMDO'></ul>
            <legend id='gYMDO'><style id='gYMDO'><dir id='gYMDO'><q id='gYMDO'></q></dir></style></legend>
          • <small id='gYMDO'></small><noframes id='gYMDO'>

              <tbody id='gYMDO'></tbody>

                  本文介紹了Java:帶有char數(shù)組的println給出亂碼的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                  問(wèn)題描述

                  這就是問(wèn)題所在.這段代碼:

                  String a = "0000";System.out.println(a);char[] b = a.toCharArray();System.out.println(b);

                  返回

                  <上一頁(yè)>00000000


                  但是這段代碼:

                  String a = "0000";System.out.println("字符串 a:" + a);char[] b = a.toCharArray();System.out.println("char[] b:" + b);

                  返回

                  <上一頁(yè)>字符串 a:0000字符 [] b: [C@56e5b723


                  世界上到底發(fā)生了什么?似乎應(yīng)該有一個(gè)足夠簡(jiǎn)單的解決方案,但我似乎無(wú)法弄清楚.

                  解決方案

                  當(dāng)你說(shuō)

                  System.out.println(b);

                  它導(dǎo)致調(diào)用 print(char[] s) 然后 println()

                  print(char[] s) 的 JavaDoc 說(shuō):

                  <塊引用>

                  打印一個(gè)字符數(shù)組.字符轉(zhuǎn)換為字節(jié)根據(jù)平臺(tái)的默認(rèn)字符編碼,而這些字節(jié)完全按照 write(int) 方法的方式寫入.

                  所以它會(huì)逐字節(jié)打印出來(lái).

                  當(dāng)你說(shuō)

                  System.out.println("char[] b: " + b);

                  這會(huì)導(dǎo)致調(diào)用 print(String),因此您實(shí)際上正在做的是將 String 附加到 Object它在 Object 上調(diào)用 toString() - 這與默認(rèn)情況下的所有 Object 以及在 Array 的情況下一樣,打印引用的值(內(nèi)存地址).

                  你可以這樣做:

                  System.out.println("char[] b: " + new String(b));

                  請(qǐng)注意,這是錯(cuò)誤的",因?yàn)槟魂P(guān)心編碼并且使用系統(tǒng)默認(rèn)值.盡早了解編碼.

                  Here's the problem. This code:

                  String a = "0000";
                   System.out.println(a);
                  char[] b = a.toCharArray();
                   System.out.println(b);
                  

                  returns

                  0000
                  0000
                  


                  But this code:

                  String a = "0000";
                   System.out.println("String a: " + a);
                  char[] b = a.toCharArray();
                   System.out.println("char[] b: " + b);
                  

                  returns

                  String a: 0000
                  char[] b: [C@56e5b723
                  


                  What in the world is going on? Seems there should be a simple enough solution, but I can't seem to figure it out.

                  解決方案

                  When you say

                  System.out.println(b);
                  

                  It results in a call to print(char[] s) then println()

                  The JavaDoc for print(char[] s) says:

                  Print an array of characters. The characters are converted into bytes according to the platform's default character encoding, and these bytes are written in exactly the manner of the write(int) method.

                  So it performs a byte-by-byte print out.

                  When you say

                  System.out.println("char[] b: " + b);
                  

                  It results in a call to print(String), and so what you're actually doing is appending to a String an Object which invokes toString() on the Object -- this, as with all Object by default, and in the case of an Array, prints the value of the reference (the memory address).

                  You could do:

                  System.out.println("char[] b: " + new String(b));
                  

                  Note that this is "wrong" in the sense that you're not paying any mind to encoding and are using the system default. Learn about encoding sooner rather than later.

                  這篇關(guān)于Java:帶有char數(shù)組的println給出亂碼的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(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ǔ)?)
                1. <legend id='xzN73'><style id='xzN73'><dir id='xzN73'><q id='xzN73'></q></dir></style></legend>
                  <i id='xzN73'><tr id='xzN73'><dt id='xzN73'><q id='xzN73'><span id='xzN73'><b id='xzN73'><form id='xzN73'><ins id='xzN73'></ins><ul id='xzN73'></ul><sub id='xzN73'></sub></form><legend id='xzN73'></legend><bdo id='xzN73'><pre id='xzN73'><center id='xzN73'></center></pre></bdo></b><th id='xzN73'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='xzN73'><tfoot id='xzN73'></tfoot><dl id='xzN73'><fieldset id='xzN73'></fieldset></dl></div>

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

                      <bdo id='xzN73'></bdo><ul id='xzN73'></ul>
                        <tbody id='xzN73'></tbody>
                      <tfoot id='xzN73'></tfoot>

                            主站蜘蛛池模板: 成人免费在线播放视频 | 日本大香伊一区二区三区 | 岛国视频| 夜夜摸天天操 | 国产一区中文 | 免费在线性爱视频 | 浮生影院免费观看中文版 | 国产精品福利在线观看 | 秋霞电影一区二区三区 | 九九99久久 | 在线色网 | 在线欧美一区 | 日韩日韩日韩日韩日韩日韩日韩 | 精品一区二区三区在线观看国产 | 国产精品久久久久一区二区三区 | 一区二区三区免费在线观看 | 久久久精品一区 | 午夜寂寞福利视频 | 成人在线视频一区二区三区 | 亚洲91精品 | 午夜影院在线视频 | 男女爱爱网站 | 超碰网址 | 毛片网站在线观看 | 婷婷五月色综合香五月 | 亚洲精品视频导航 | 成人精品在线视频 | 自拍偷拍av | 日韩在线综合 | 欧美日韩视频一区二区 | 免费a大片 | 91在线看 | 国产精品一区二区在线免费观看 | 成人欧美一区二区三区在线播放 | 日韩在线播放av | 香蕉视频在线播放 | 欧美性受xxxx| 日日夜夜天天 | 91精品国产色综合久久 | 99riav国产一区二区三区 | 欧美激情国产日韩精品一区18 |