构造方法:
1.空参数的构造方法
String s1 = new String();
2.通过字节数组创建的字符串对象
byte[] by = {97,98,99,100};
String s2 = new String(by);
System.out.println(s2);
System.out.println(s2.length());
3.通过字符数组创建的字符串对象
byte[] by1 = {'a','b','c','d','e','f'};
String s3 = new String(by1);
System.out.println(s3);
System.out.println(s3.length());
4.直接给字符串对象赋值,最常用
String s4 = "hello";
System.out.println(s4);
System.out.println(s4.length());
|
|