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