没有替换所有输出:[3, 2, 1]
使用替换输出:3,2,1
无论如何使用单个replaceAll方法来做到这一点,比如
set.toString().replaceAll("\\[\\]\\s+","");
现在代码
Set<String> set = new HashSet<String>();
set.add("1");
set.add("2");
set.add("3");
System.out.println(set.toString().replaceAll("\\[", "").replaceAll("\\]", "").replaceAll("\\s+", ""));