Using BigDecimal to validate epoch timestamp in exponential notation I have some phone records in which epoch time is coming in exponential format like 1467.738871E9. I need to validate those records in which number is not in proper format and drop those records. Right now, I am using big decimal, but I have heard that bigdecimal is slow and takes more space. Since I have million of records to be validated, is there any other way to validate time which is more space- and time-efficient?

try{
    new BigDecimal(data).toBigInteger();}
    catch(NumberFormatException n){
      return false;
    } 
return true;


Examples of valid timestamps:


1.467983982E9
1.468119771E9
1467858808E9
1.468119771E11
1468119771E11


Examples of invalid timestamps:


1.46A802215E9
null
4.1B46A802215E9
There's no point in calling toBigInteger since that doesn't throw anything. You might as well just have this:

try {
    new BigDecimal(data);
} catch(NumberFormatException n) {
    return false;
}
return true;


Or you might consider using toBigIntegerExact if you don't allow fractional parts in the number (e.g. 1.2345E3 which is 1234.5 is not allowed):

try {
    new BigDecimal(data).toBigIntegerExact();
} catch(NumberFormatException | ArithmeticException e) {
    return false;
}
return true;


Also, have you thought about whether negative numbers should be allowed?

Regarding time &amp; space performance, it will create one BigDecimal object (and possibly one BigInteger object) for every valid record. It will then release it as eligible for garbage collection. The JIT compiler will probably optimize this to make it insignificant compared to the time it takes to read and write the records.