public class Test { public static void main(String[] args) { String s = "ni\nhao\nma he yi\nyong"; String[] strs = s.split("\\n| "); for(String string : strs) { System.out.println(string); } } }
一個字符串同時匹配換行和空格,最終輸出:spa
nihaomaheyiyongcode