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

17 lines
571 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 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);
}
}
}