package com.wyq.test;
public class TestStr {
public static void main(String[] args) {
String str = "abc";
char[] c = { 'a', 'b', 'c' };
String str2 = new String(c);//使用string中的構造方法,可以將char類型的數組轉換成string類型
String str3 = new String(c, 1, 2);// 索引为1的位置,长度为2个
System.out.println(str3);
System.out.println("str == str2" + (str == str2));
System.out.println("str.equals(str2)" + (str.equals(str)));
byte[] b = { 97, 98, 99, 100 };
String str4 = new String(b);//使用構造方法,将char类型的数组转换成String类型
System.out.println(str4);
System.out.println(new String(b, 2, 2));// 在b數組中,從索引為2的位置開始取,一共取2個
}
}
最典型的的应用是将char类型的数组转换成string类型