What's the best way to check if a String represents an integer in Java?

后端 未结 30 1488
野趣味
野趣味 2020-11-22 05:45

I normally use the following idiom to check if a String can be converted to an integer.

public boolean isInteger( String input ) {
    try {
        Integer.         


        
30条回答
  •  难免孤独
    2020-11-22 06:20

    org.apache.commons.lang.StringUtils.isNumeric 
    

    though Java's standard lib really misses such utility functions

    I think that Apache Commons is a "must have" for every Java programmer

    too bad it isn't ported to Java5 yet

提交回复
热议问题