As indicated in the commentary, one of the lines may be number, and the other is not, or vice versa, or both may be string, therefore, instead of checking whether the lines are numeric lines, I will use a try catchblock.
Like this:
try{
Double d1 = Double.parseDouble(str1);
Double d2 = Double.parseDouble(str2);
System.out.println(d1.equals(d2));
}catch(NumberFormatException ex){
System.out.println(num1.equals(num2));
}
At first he tries to compare them as numbers, but if at least one of them is not a numeric string, she will depart from comparing the strings in the block catch.
source
share