Java字符串和字節數組的相互轉換


示例代碼如下所示

public class test {
    public static void main(final String[] args) {
       String s="Hello world!";
       System.out.println(s);

       //字符串轉換為字節數組
       byte []a=s.getBytes();
       for(int i=0;i<a.length;i++)
       {
           System.out.print(a[i]+" ");
       }
       System.out.println(s);
        
       //字節數組轉換為字符串
       String str=new String(a);
       System.out.println(str);
    }
    
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM