I know that I can match numbers with Pattern.compile("\\d*");
But it does not handle long min / max values.
For performance issues related to exceptions, I don't want to try to parse a long one if it is really long.
if ( LONG_PATTERN.matcher(timestampStr).matches() ) {
long timeStamp = Long.parseLong(timestampStr);
return new Date(timeStamp);
} else {
LOGGER.error("Can't convert " + timestampStr + " to a Date because it is not a timestamp! -> ");
return null;
}
I mean, I donβt want any try / catch block, and I donβt want to get exceptions thrown over time like β564654954654464654654567879865132154778β, which is not the size of a regular Java long.
Does anyone have a template to handle this kind of needs for primitive Java types? Does the JDK provide something to process it automatically? Is there any safe parsing in Java?
thank
: , " " .
, , .
, , , , % " " ββ
, StackOverflow, , sams , LOT , , , , , .