code_junkie

Simplest way to print an array in Java

Nov 13th, 2011
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. int[] intArray = new int[] {1, 2, 3, 4, 5};
  2. //output: [1, 2, 3, 4, 5]
  3.  
  4. String[] strArray = new String[] {"John", "Mary", "Bob"};
  5. //output: [John, Mary, Bob]
  6.  
  7. System.out.println(Arrays.toString(array));
  8.  
  9. System.out.println(Arrays.deepToString(array));
  10.  
  11. import java.util.Arrays;
  12. .
  13. .
  14. .
  15. System.out.println( Arrays.toString( myarray ) );
  16.  
  17. System.out.println(Arrays.asList(array));
Add Comment
Please, Sign In to add comment