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. public static void main(String[] args) {
  11. System.out.println(toString(new int[] {1,2,3,4,5,6,7,8,9,10}, '<', '>', " - "));
  12. }
  13.  
  14. public static String toString(int[] a, char start, char end, String space)
  15. {
  16. int len = a.length;
  17. StringBuilder builder = new StringBuilder(len + (len - 1) * space.length() + 2);
  18. builder.append(start);
  19.  
  20. for (int i = 0; i < len; i++) {
  21. if (i != 0) builder.append(space);
  22. builder.append(a[i]);
  23. }
  24.  
  25. builder.append(end);
  26.  
  27. return builder.toString();
  28. }
  29. }
Success #stdin #stdout 0.07s 380224KB
stdin
Standard input is empty
stdout
<1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10>