日々精進

新しく学んだことを書き留めていきます

文字列をBigDecimalやInteger等に変換出来るかどうかを判定する

以下のように例外をキャッチして判定するしかないっぽい。tryParse的なメソッドがあるのかと思ったけど。。無いならしょうがない。

try {  
    new BigDecimal("some string"); // This do nothing because the instance is ignored  
} catch (NumberFormatException e) {  
    return false; // OK, the string wasn't a well-formed decimal  
}  
return true;

参考: