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

17 lines
520 B
Java
Raw 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 Example04 {
public static void main(String[] args) {
String name = "王小明";
String newName = name.replace("", "");
System.out.println("旧名字:" + name + "\n新名字" + newName);
System.out.println();
String name2 = " 王 小明 ";
String name3 = name2.trim();
System.out.println("去除空格前:" + name2 + "\n去除空格后" + name3 );
// 思考:如何去掉所有空格?
}
}