String 类的两种实例化方式
- 直接赋值
String str = "Hello World!!"; System.out.println(str);
- 利用构造函数完成,通过关键字new
String strs = new String ("Hello World!"); System.out.println(strs);
- 创建字符数组
char[] chars = new char[]{'H','e','l','l','o','W','o','r','l','d','!'}; for (int i = 0; i<chars.length ; i++){ System.out.print(chars[i]); }