join   JAVA


Summary

Returns a new String composed of copies of the CharSequence elements joined together with a copy of the specified delimiter.


public static String join(CharSequence delimiter, CharSequence... elements)
public static String join(CharSequence delimiter, Iterable<? extends CharSequence> elements)

public class StringJoin {
  public static void main(String args[]) {
    String str = String.join("-", "a", "b", "c");  
    System.out.println(str);

    List<String> strs = Arrays.asList("d", "e", "f");
    System.out.println( String.join("-", strs) );
  }
}


Result

a-b-c
d-e-f

References


Tags

#array  #explode  #implode  #join  #split  #stringtokenizer  #tokenizer 


[ Edit (Author only) ]