Checking if a number is an Integer in Java

后端 未结 11 493
生来不讨喜
生来不讨喜 2020-12-09 15:48

Is there any method or quick way to check whether a number is an Integer (belongs to Z field) in Java?

I thought of maybe subtracting it from the rounded number, but

11条回答
  •  囚心锁ツ
    2020-12-09 16:23

    With Z I assume you mean Integers , i.e 3,-5,77 not 3.14, 4.02 etc.

    A regular expression may help:

    Pattern isInteger = Pattern.compile("\\d+");
    

提交回复
热议问题