[AppleScript] 纯文本查看 复制代码 String s = new String(); //public String():空构造
System.out.println(s);
byte [] arr = {97,98,99};//public String(byte[] bytes):把字节数组转成字符串(下面是用法)
String s1 = new String(arr);
System.out.println(s1);//结果是abc
byte [] arr1 = {97,98,99,100,101,102,103,104};//public String(byte[] bytes,int index,int length):把字节数组的一部分转成字符串
String s2 = new String(arr1,2,4);//将数组中的数据,从索引值为2的开始,转换成字符串,一共连续转换4个
System.out.println(s2);//结果是cdef
char [] arr2 = {'a','b','b','c','d'};//public String(char[] value):把字符数组转成字符串
String s3 = new String(arr2);
System.out.println(s3);//最后输出的是:abbcd这样的字符串
char [] arr3 = {'a','b','c','d','e'}; //public String(char[] value,int index,int count):把字符数组的一部分转成字符串
String s4 = new String(arr3,2,3);//把索引2开始的字符数转换成字符串,转换3个
System.out.println(s4);//结果是cde
String s5 = "abcdr";//public String(String original):把字符串常量值转成字符串
String s6 = new String(s5);
System.out.println(s5); |