提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
用正则表达式分割字符串
import java.util.regex.Pattern; import java.util.regex.Matcher;/** 来 自 N o w J a v a . c o m**/ public class SplitDemo { private static final String REGEX = ":"; private static final String INPUT = "one:two:three:four:five"; public static void main(String[] args) { Pattern p = Pattern.compile(REGEX); String[] items = p.split(INPUT); for (String s : items) { System.out.println(s); }/*来 自 nowjava.com*/ } }