fork download
  1. import java.util.*;
  2. import java.lang.reflect.*;
  3.  
  4. class Main
  5. {
  6. public static String toString(Object a)
  7. {
  8. Class clazz = Object[].class.isAssignableFrom(a.getClass()) ? Object[].class : a.getClass();
  9. Method method = Arrays.class.getMethod("toString", new Class[] { clazz } );
  10. return (String)method.invoke(null, new Object[] { a });
  11. }
  12.  
  13. public static void main(String[] args) throws Exception
  14. {
  15. int[] test1 = { 1, 2, 3 };
  16. System.out.println(toString(test1));
  17. String[] test2 = { "a", "b", "c" };
  18. System.out.println(toString(test2));
  19. }
  20. }
  21.  
Success #stdin #stdout 0.05s 213440KB
stdin
Standard input is empty
stdout
[1, 2, 3]
[a, b, c]