String’s join method can be used to join various String by the delimiter. It is introduced in java 8.
For example: We need to join various Strings by “,”. You can use join method as
1 2 3 4 5 |
String.join(",","java","blog","tutorials"); // Output "java,blog,tutorial" |
1 2 3 4 5 |
public static String join(CharSequence delimiter, CharSequence... elements) and public static String join(CharSequence delimiter, Iterable elements) |
String join example:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
package org.arpit.java2blog; public class StringJoinExample { public static void main(String[] args) { System.out.println(String.join(",","java","blog","tutorials")); System.out.println(String.join("-","java","blog","tutorials")); } } |
When you run above program, you will get below output:
java,blog,tutorials
java-blog-tutorials
java-blog-tutorials
Was this post helpful?
Let us know if this post was helpful. Feedbacks are monitored on daily basis. Please do provide feedback as that\'s the only way to improve.