How to check type of variable in Java?

前端 未结 14 1649
别跟我提以往
别跟我提以往 2020-11-28 05:14

How can I check to make sure my variable is an int, array, double, etc...?

Edit: For example, how can I check that a variable is an array? Is there some function to

14条回答
  •  甜味超标
    2020-11-28 05:49

    Just use:

    .getClass().getSimpleName();
    

    Example:

    StringBuilder randSB = new StringBuilder("just a String");
    System.out.println(randSB.getClass().getSimpleName());
    

    Output:

    StringBuilder
    

提交回复
热议问题