常见的构造方法
案例演示
public class StringGouZao {
public static void main(String[] args) {
String s1 = new String ( ); //空构造
System.out.println (s1);
byte[] arr1 = {97 , 98 , 99};
String s2 = new String (arr1); //将字节数转化成字符串
System.out.println (s2);
byte[] arr2 = {97 , 98 , 99 , 100 , 101};
String s3 = new String (arr2 , 2 , 3); //把字节数组的一部分转化成字符串
System.out.println (s3);
char[] arr3 = {97 , 98 , 99 , 100 , 101};
String s4 = new String (arr3); //把字符数组转化成字符串
System.out.println (s4);
char[] arr4 = {97 , 98 , 99 , 100 , 101};
String s5 = new String (arr4 , 2 , 2); //把字符数组的一部分转化成字符串
System.out.println (s5);
String s6 = new String ("hello"); //把字符常量值转化成字符串
System.out.println (s6);
}
}