Program
public class StringJoin { public static void main(String[] args) { String date = String.join("/","01","03","1999"); System.out.println(date); String time = String.join(":", "05","30","10"); System.out.println(""+time); } }
Output
01/03/1999 05:30:10
Description
public static String join(CharSequence delimiter, CharSequence… elements)
Returns a new String composed of copies of the CharSequence elements joined together with a copy of the specified delimiter.
Parameters:
delimiter – the delimiter that separates each element
elements – the elements to join together.
Returns:
a new String that is composed of the elements separated by the delimiter
Throws:
NullPointerException – If delimiter or elements is null
Since:
1.8