package string; public class split { public static void main(String[] args) { /** * 字符串的分割 */ String str = "www.baidu.com"; String[] temp = str.split("\\.");// "."和“|”都需要加上\\转译 for (int i = 0; i < temp.length; i++) { System.out.println(temp[i]); } System.out.println("============使用for each=========="); String str1 = "abc-cdef-ghij"; String[] temp1 = str1.split("-"); for (String x : temp1) { System.out.println(x); } } }