split() -- 字符串的切割函数 replaceAll()--字符串的替换函数
程序员文章站
2022-07-14 12:14:25
...
public static void main(String[] args) {
replaceAll();
split_01();
split_02();
split_03();
}
private static void split_03() {
String str = "127.903.22.2.123";
String[] strs = str.split("\\.");
System.out.println("数组的长度是:"+strs.length);
for(int i=0;i<strs.length;i++){
System.out.println(strs[i]);
}
}
private static void split_02() {
String str = "22 342 * 324 ";
String[] strs = str.split(" +");
System.out.println("数组的长度是:"+strs.length);
for(int i=0;i<strs.length;i++){
System.out.println(strs[i]);
}
}
private static void split_01() {
String str = "188-2348-2249";
String strs[] = str.split("-");
System.out.println("数组长度是:"+strs.length);
for(int i =0;i<strs.length;i++){
System.out.println(strs[i]);
}
}
private static void replaceAll() {
String str = "Hello12345World6789012";
str = str.replaceAll("[\\d]+", "#");
System.out.println(str);
}
上一篇: Ubuntu 18.04重装及配置
下一篇: ArrayList源码学习(2)