📜  Java StringBuilder 过滤相同的行 - Java 代码示例

📅  最后修改于: 2022-03-11 14:52:36.508000             🧑  作者: Mango

代码示例1
Set tokens = new HashSet(Arrays.asList(s.split("\n")));
StringBuilder resultBuilder = new StringBuilder();

boolean first = true;
for(String token : tokens) {
    if(first) first = false;
    else resultBuilder.append("\n")

    resultBuilder.append(token);
}

String result = resultBuilder.toString();