5.1 String类
This commit is contained in:
24
src/chapter5/Example03.java
Normal file
24
src/chapter5/Example03.java
Normal 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());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user