Java2024/src/chapter5/Example03.java
2024-11-06 13:16:26 +08:00

25 lines
874 B
Java
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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());
}
}