Before asking for help , i am really sorry if this is a duplicate question or bad question because i did not know what to search.
There is a thing that is bothering me while playing with arrays in java. Here is code:
String []stt = new String[5];
stt[0].length(); //of course NullPointerException because uninitialized.
System.out.println(stt.getClass()); //it should return class of array instead of String.
According to above code, there is no String Object created till now and stt should be of Array type not String type ,in fact elements inside stt should be of String type.
I wanted to know what is the class of array objects and it is supposed to return class of array objects.
The class of what the reference is pointing to is a String array. if you want to test to see if that reference is part of an array, then there is a special method for that, isArray
.
System.out.println(stt.getClass().isArray());
As some other have noted, with a closer look you can see the difference in the output just using
class [Ljava.lang.String; // Array of String
class java.lang.String // String