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