fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10.  
  11. public static String getArrayAsString(String[] stringArray, String separator) {
  12. if(stringArray == null || stringArray.length == 0) return "";
  13.  
  14. StringBuilder finalString = new StringBuilder(stringArray[0]);
  15.  
  16. for(int i = 1; i < stringArray.length; ++i)
  17. finalString.append(separator).append(stringArray[i]);
  18.  
  19. return finalString.toString();
  20. }
  21.  
  22. public static void main (String[] args) throws java.lang.Exception
  23. {
  24. String[] arr = new String[]{"Hello", "World"};
  25. System.out.println(String.join(" | ", arr));
  26. System.out.println(getArrayAsString(arr, " | "));
  27. }
  28. }
Success #stdin #stdout 0.04s 711168KB
stdin
Standard input is empty
stdout
Hello | World
Hello | World