I am reading from many large text files and I have to check if each snippet of text contains a double value or not. The regex code I am currently using is causing my program to run very slowly because in total I am checking 10 billion strings. I know that due to the large number of strings that I am checking, my program is bound to run slowly. But is there a more efficient and quicker way to check if a String is a double value, thus decreasing the runtime of the program? Thanks
if (string[i].matches(".*\\d.*")) {
.....
}
Also, the strings from the text file are read into an array before the I check them, therefore time isn't wasted constantly reading the text file.
Use the Pattern and Matcher classes:
public static final Pattern DOUBLE = Pattern.compile("\\d");
...
if (DOUBLE.matcher(string[i]).find()) {
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With