1// Java program to demonstrate working of Arrays.toString()
2import java.io.*;
3import java.util.*;
4
5class GFG {
6 public static void main(String[] args)
7 {
8 // Let us create different types of arrays and
9 // print their contents using Arrays.toString()
10 boolean[] boolArr = new boolean[] { true, true, false, true };
11 byte[] byteArr = new byte[] { 10, 20, 30 };
12 char[] charArr = new char[] { 'g', 'e', 'e', 'k', 's' };
13 double[] dblArr = new double[] { 1, 2, 3, 4 };
14 float[] floatArr = new float[] { 1, 2, 3, 4 };
15 int[] intArr = new int[] { 1, 2, 3, 4 };
16 long[] lomgArr = new long[] { 1, 2, 3, 4 };
17 Object[] objArr = new Object[] { 1, 2, 3, 4 };
18 short[] shortArr = new short[] { 1, 2, 3, 4 };
19
20 System.out.println(Arrays.toString(boolArr));
21 System.out.println(Arrays.toString(byteArr));
22 System.out.println(Arrays.toString(charArr));
23 System.out.println(Arrays.toString(dblArr));
24 System.out.println(Arrays.toString(floatArr));
25 System.out.println(Arrays.toString(intArr));
26 System.out.println(Arrays.toString(lomgArr));
27 System.out.println(Arrays.toString(objArr));
28 System.out.println(Arrays.toString(shortArr));
29 }
30}
31
1// Java program to demonstrate working of Arrays.toString()
2import java.io.*;
3import java.util.*;
4
5class GFG {
6 public static void main(String[] args)
7 {
8 // Let us create different types of arrays and
9 // print their contents using Arrays.toString()
10 boolean[] boolArr = new boolean[] { true, true, false, true };
11 byte[] byteArr = new byte[] { 10, 20, 30 };
12 char[] charArr = new char[] { 'g', 'e', 'e', 'k', 's' };
13 double[] dblArr = new double[] { 1, 2, 3, 4 };
14 float[] floatArr = new float[] { 1, 2, 3, 4 };
15 int[] intArr = new int[] { 1, 2, 3, 4 };
16 long[] lomgArr = new long[] { 1, 2, 3, 4 };
17 Object[] objArr = new Object[] { 1, 2, 3, 4 };
18 short[] shortArr = new short[] { 1, 2, 3, 4 };
19
20 System.out.println(Arrays.toString(boolArr));
21 System.out.println(Arrays.toString(byteArr));
22 System.out.println(Arrays.toString(charArr));
23 System.out.println(Arrays.toString(dblArr));
24 System.out.println(Arrays.toString(floatArr));
25 System.out.println(Arrays.toString(intArr));
26 System.out.println(Arrays.toString(lomgArr));
27 System.out.println(Arrays.toString(objArr));
28 System.out.println(Arrays.toString(shortArr));
29 }
30}
1int[] numbers = new int[10];
2
3int[] names = new String[]{"John", "Jack"};
4
5int length = names.length;
6
7for (String name: names) {
8 System.out.println(name);
9}