.join()
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.
Syntax
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.
Example
The example below uses .join()
to concatenate several names with a pipe delimiter:
// JoinPipe.javaclass JoinPipe {public static void main(String[] args) {String names = String.join(" | ", "Carl", "Jonas", "Emily", "Daniel", "Nina");System.out.println(names);}}
The output would be:
Carl | Jonas | Emily | Daniel | Nina
All contributors
- Anonymous contributor
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.