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,24 @@
package chapter5;
public class Example03 {
public static void main(String[] args) {
String str = "abcdEFG";
// 1、转换成字符数组
System.out.print("将字符串转为字符数组后的结果:");
char[] charArray = str.toCharArray();
for (char c : charArray) {
System.out.print(c); // 打印当前遍历到的字符
System.out.print(','); // 每打印一个字符后,加一个逗号
}
// 2、把数字转换成字符串好用
System.out.println();
System.out.print("把数字123转换成字符串的效果");
System.out.println(String.valueOf(123));
// 3、大小写转换常用
System.out.println("转换成小写:" + str.toLowerCase());
System.out.println("转换成大写:" + str.toUpperCase());
}
}