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,16 @@
package chapter5;
public class Example06 {
public static void main(String[] args) {
String str = "石家庄-武汉-哈尔滨";
// 1、截取
System.out.println("从第5个字符截取到末尾" + str.substring(4));
System.out.println("从第5个字符截取到第6个字符" + str.substring(4, 6));
// 2、分割
System.out.println("分割后字符串数组中的元素依次是:");
String[] array = str.split("-");
for (String s : array) {
System.out.println(s);
}
}
}