java各种类型转换

1、String与char、char[]转换:

      String str = "hello world!";

      char[] ch = str.toCharArray();//String转char[]

      String str1 = String.valueOf(ch);//char[]转String

      String str2 = new String(ch);//char[]转String

      char ca = str.charAt(0);//String转char

      String str3 = ca + "";//char转String

 

2、String与byte[]转换:

      String str = "hello world!哈哈";
      byte[] bt1 = str.getBytes();//String转byte[]
      byte[] bt2 = str.getBytes("utf-8");//String使用指定编码转byte[]

      String str1 = new String(bt1);//byte[]转String
      String str2 = new String(bt2,"utf-8");//byte[]使用指定指定编码转String

后续更新中......

你可能感兴趣的:(职场,休闲,java各种类型转换)