ob1kanobee
Programmer
Is there a better or more efficient way of assessing this information? Values being compared will always be the same length and are already being verified for Letter or Digit values only. Values may be all numeric or all alphabetic or combination of both. I want to know when first value is greater than second value.
String value1 = "A22B7A9X";
String value2 = "A22C7A9X";
boolean isGreater = false;
for(int x = 0 ;x < value1.length(); x++)
{
if(value1.substring(x,x+1).hashCode() > value2.substring(x,x+1).hashCode())
{
isGreater = true;
break;
}
}
if(isGreater)
System.out.println("Value 1 IS greater than Value 2");
else
System.out.println("Value 1 IS NOT greater than Value 2");
String value1 = "A22B7A9X";
String value2 = "A22C7A9X";
boolean isGreater = false;
for(int x = 0 ;x < value1.length(); x++)
{
if(value1.substring(x,x+1).hashCode() > value2.substring(x,x+1).hashCode())
{
isGreater = true;
break;
}
}
if(isGreater)
System.out.println("Value 1 IS greater than Value 2");
else
System.out.println("Value 1 IS NOT greater than Value 2");