Skip to content

Instantly share code, notes, and snippets.

@bxb100
Created May 8, 2022 08:57
Show Gist options
  • Save bxb100/3efa4a7676455670d58a0e3dc4415ac4 to your computer and use it in GitHub Desktop.
Save bxb100/3efa4a7676455670d58a0e3dc4415ac4 to your computer and use it in GitHub Desktop.
Best way to join the String
import java.util.StringJoiner;
import java.util.stream.Stream;
public class StringDemo {
public static void main(String[] args) {
StringJoiner sj = new StringJoiner(",", "[", "]");
Stream.of("1", "2", "3").forEach(sj::add);
System.out.println(sj.toString());
}
}
@bxb100
Copy link
Author

bxb100 commented May 8, 2022

since Java 1.8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment