Arrays are builtin with Java itself, you can't find a class for it like you would for example String
.
Arrays are Objects in java, that's true.
When we write a statement, int a[]=new int[56];
Here int is a primitive, it cannot be the class used for defining
array objects...
int
does represent primitive type values, but the object(array) is not of int
type it just contains elements of type int
.
can you tell me how arr.length works if we say arr is an object
Arrays ARE Objects as we already stated, length is a FIELD/ATTRIBUTE that every instance of array contains, that field is final and is created once you instantiate array:
int[] arrayOfInts = new int[23];
As you can see above we specify 23 for the size of our int[]
and that size will be assigned to length
field when our array is created, and we already said it's final so it can't be reassigned, we can only create new array not resize the current one.
Hope I cleared some of your confusion.