Anonymous contributor's avatar
Anonymous contributor
Anonymous contributor's avatar
Anonymous contributor
Published Mar 5, 2023
Contribute to Docs

The .join() method returns a new string composed of the elements joined together with the specified delimiter.


String.join(delimiter, element1, element2...elementN);
  • delimiter (required): The delimiter that is used to join the elements.
  • elements(required): The elements to be joined together.


The example below uses .join() to concatenate several names with a pipe delimiter:

// JoinPipe.java
class JoinPipe {
public static void main(String[] args) {
String names = String.join(" | ", "Carl", "Jonas", "Emily", "Daniel", "Nina");

The output would be:

Carl | Jonas | Emily | Daniel | Nina

All contributors

Looking to contribute?

Learn Java on Codecademy