久久久久久久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數組的println給出亂碼

        Java: println with char array gives gibberish(Java:帶有char數組的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數組的println給出亂碼的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  這就是問題所在.這段代碼:

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

                  返回

                  <上一頁>00000000


                  但是這段代碼:

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

                  返回

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


                  世界上到底發生了什么?似乎應該有一個足夠簡單的解決方案,但我似乎無法弄清楚.

                  解決方案

                  當你說

                  System.out.println(b);

                  它導致調用 print(char[] s) 然后 println()

                  print(char[] s) 的 JavaDoc 說:

                  <塊引用>

                  打印一個字符數組.字符轉換為字節根據平臺的默認字符編碼,而這些字節完全按照 write(int) 方法的方式寫入.

                  所以它會逐字節打印出來.

                  當你說

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

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

                  你可以這樣做:

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

                  請注意,這是錯誤的",因為您不關心編碼并且使用系統默認值.盡早了解編碼.

                  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.

                  這篇關于Java:帶有char數組的println給出亂碼的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 原語?)
                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>

                            主站蜘蛛池模板: 成人在线不卡 | 久久国产欧美日韩精品 | 欧美 日韩 在线播放 | 国产精品视频一 | 国产精品揄拍一区二区 | 欧美一区久久 | 国产亚洲一区二区精品 | 中文字幕在线观看一区二区 | 成人免费在线 | 免费在线观看av的网站 | 一区二区三区视频在线观看 | 黄篇网址 | 日本在线视频中文字幕 | av不卡一区 | 黄网站在线播放 | 久久久久久天堂 | 欧美精品一区二区三区在线 | 成人毛片视频在线播放 | 91在线视频免费观看 | www国产成人免费观看视频,深夜成人网 | 成人性视频免费网站 | 欧美精品一区二区免费 | 天天综合天天 | 国产精品一区二区免费 | 天天躁日日躁狠狠的躁天龙影院 | 精品国产一区一区二区三亚瑟 | 国产一级网站 | 在线免费观看日本视频 | 亚州精品天堂中文字幕 | 国产精品一二区 | 男人电影天堂 | 日韩亚洲一区二区 | 麻豆一区一区三区四区 | 欧美精品一区免费 | 精品自拍视频 | 午夜专区| 日韩一区二区三区视频 | 国产精品av久久久久久毛片 | 欧美在线一区二区三区 | 欧美性大战久久久久久久蜜臀 | cao在线 |