1 package cn.itcast.p1.string.demo;
2
3 public class StringConstructorDemo {
4 public static void main(String[] args) {
5 stringConstructorDemo();
6 stringConstructorDemo2();
7 }
8
9 private static void stringConstructorDemo2() {
10 char[] arr = {'w','a','p','q','x'};
11 String s = new String(arr,1,3);//String(char[] value,int offset,int count)
12 System.out.println("s="+s);
13
14 }
15
16 public static void stringConstructorDemo() {
17
18 String s = new String();//等效于String s = "";不等效于String s = null;
19
20 byte[] arr = {97,66,67,68};
21
22 String s1 = new String(arr);
23 System.out.println("s1="+s1);
24 }
25
26 }