+ 1
How to know datatype of a variable in Java ?
In python we have type() function but how can i know the datatype of variable in Java?
3 Réponses
+ 3
Depends what you exactly mean by a variable. But for an object it should be getName and getClass.
Also there is something called instanceOf which I think for the array list
+ 3
You can find the type only for reference type variables.
String str = "hello";
System.out.println(str instanceof String);
OR
System.out.println(
str.getClass().getName());