- 1

How to check if a type is a primtive array in Java?

15th Dec 2019, 1:57 PM
Vikram Singh
Vikram Singh - avatar
2 Respostas
+ 2
An array itself is always an object, only the elements inside it can be primitive. It also can store objects. Eg - int[] arr = new int[5]; Here arr is an object and it can store 5 integer type elements.
15th Dec 2019, 2:31 PM
Avinesh
Avinesh - avatar
+ 2
As Avinesh mentioned arrays are objects. So you can use getClass().getSimpleName() to check if the array contains primitves. This method returns a String: int[] arr -> arr.getClass().getSimpleName() returns "int[]" https://code.sololearn.com/calrsLqa05b6/?ref=app
15th Dec 2019, 6:35 PM
Denise Roßberg
Denise Roßberg - avatar