public class Test { public static void main(String[] args) { String s1 = "string demo test"; // 待拆分字符串 String s11[] = s1.split(" "); for (int i = 0; i < s11.length; i++) { System.out.println(s11[i]); } String s2 = "string-demo-test"; // 待拆分字符串 String s22[] = s2.split("-"); // 根据任意字符串拆分(+ * | 等字符不可以) for (int i = 0; i < s22.length; i++) { System.out.println(s22[i]); } } }