Most elegant way to detect if a String is a number?

前端 未结 11 831

Is there a better, more elegant (and/or possibly faster) way than

boolean isNumber = false;
try{
   Double.valueOf(myNumber);
   isNumber = true;
} catch (Nu         


        
11条回答
  •  情书的邮戳
    2020-12-30 12:02

    I would use the Jakarta commons-lang, as always ! But I have no idea if their implementation is fast or not. It doesnt rely on Exceptions, which might be a good thig performance wise ...

提交回复
热议问题