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); } } }
一个字符串同时匹配换行和空格,最终输出:
ni
hao
ma
he
yi
yong
时间: 2024-10-14 07:38:22