Answers for "Java StringBuilder filter same lines"

0

Java StringBuilder filter same lines

Set<String> tokens = new HashSet<String>(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();
Posted by: Guest on January-28-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language