Joining Strings with Java 1.8+

The static String's method join, introduced in Java 1.8, joins a String array with a passed separator:

import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;

public class StringJoinTest {
    public void joinStrings() {
        var commaSeparated = String.join(",", "hello", "world");
        assertEquals("hello,world", commaSeparated);


Amazingly, strings are a problem throughout so many languages, C, C++, Java, Python... How could something so simple as a bunch of characters represented as bytes be a major problem for our primary programming languages? Yet, that's what happened!

Posted by Kevin Farnham on October 22, 2020 at 08:46 PM CEST #

Post a Comment:
  • HTML Syntax: NOT allowed
...the last 150 posts
...the last 10 comments