1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
import java.util.Arrays; class test{ public static void main(String args[]){ int arr[] = {4,6,3,6,2,6}; String str = Arrays.toString(arr); System.out.println("1. arr to string : " + str); System.out.println("2. class of str: " + str.getClass()); System.out.println("3. class name of str: " + str.getClass().getName()); System.out.println("4. class of arr : " + arr.getClass()); System.out.println("5. class name of arr : " + arr.getClass().getName()); } } |
Discussion
This example has been compiled with JDK 9
Output
1 2 3 4 5 |
1. arr to string : [4, 6, 3, 6, 2, 6] 2. class of str: class java.lang.String 3. class name of str: java.lang.String 4. class of arr : class [I 5. class name of arr : [I |
We can see that type (class) of array can be retrived from getClass() and Name of Class with getName().
In next post we will use getClass and getName on all the data types and see what will be the results.