How to know datatype of a variable in Java ? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 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?

18th Oct 2020, 4:27 PM
Lakshay Deshraj
2 Respostas
+ 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
18th Oct 2020, 4:34 PM
Khaled ^^ Ų®Ų§Ł„ŲÆ Ų§Ł„Ł‚Ų±ŁŠŲ“ŁŠā€Ž
Khaled ^^ Ų®Ų§Ł„ŲÆ Ų§Ł„Ł‚Ų±ŁŠŲ“ŁŠā€Ž - avatar
+ 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());
18th Oct 2020, 4:40 PM
Avinesh
Avinesh - avatar