示例:输入:There is a will,there is a way. 输出There is a will there way
答案代码:
String s = "There is a will there is a way"; Pattern p = Pattern.compile("[,.]"); String ss = p.matcher(s).replaceAll(""); LinkedHashSet<String> set = new LinkedHashSet<String>(Arrays.asList(ss.split("[\\s*\t\r\n]"))); set.forEach(System.out::println);