5.1 String类

This commit is contained in:
2024-11-06 13:16:26 +08:00
parent cf6183c5b8
commit 58ad0dd15a
6 changed files with 104 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
package chapter5;
public class Example01 {
public static void main(String[] args) {
// 1、创建一个空的字符串
String str1 = new String();
// 2、创建一个内容为abcd的字符串
String str2 = new String("abcd");
// 3、创建一个内容为字符数组的字符串
char[] charArray = new char[]{'D', 'E', 'F'};
String str3 = new String(charArray);
// 4、创建一个内容为字节数组的字符串
byte[] arr = {97, 98, 99};
String str4 = new String(arr);
System.out.println("a" + str1 + "b");
System.out.println(str2);
System.out.println(str3);
System.out.println(str4);
}
}