package com.fatiaoyu;
import java.util.*;
public class Splitting {
public static String knights = “Then,when you have found the” + “cut down the mightiest tree in " + “with … a herring!”;
public static void split(String regex) {
System.out.println(Arrays.toString(knights.split(regex)));
}
public static void main(String[] args) {
split(” “);
split(”\W+ ");
split(“n\W+”);
}
}
打印结果:

该博客展示了如何使用Java的split方法根据正则表达式拆分字符串。示例中,代码将一个包含骑士语句的字符串按不同规则进行拆分,包括空格、非单词字符以及特定模式的非单词字符。
3028

被折叠的 条评论
为什么被折叠?



