Comparing string arrays

Howdy-

Does anyone know how to convert a string to an integer equivalent, probably either ASCII or EBCDIC? I need to process the following:

if(string[num1] > string[num2])

This compiler doesn't like this. I can't tell what to use from the drop-down window, if anything.

Big Thanx!

[331 byte] By [SickBunny] at [2007-9-26 1:54:37]
# 1

instead of converting them, you can compare them directly using String's compareTo() method:

instead of : if(string[num1] > string[num2])

do this:

if(string[num1].compareTo(string[num2])>0){

//this happens if string[num1] is "larger" than string[num2]

}

artntek at 2007-6-29 3:07:21 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 2

You can try the following which should work:

try {

if(Integer.parseInt(string[num1]) > Integer.parseInt(string[num2])) {

}

catch (NumberFormatException nfe) {

;

}

If the String somehow does not contain an int we can use the NumberFormatException to catch the error.

shann0nw at 2007-6-29 3:07:21 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 3
THanks artntek ;)
SickBunny at 2007-6-29 3:07:21 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 4
THanks to you too, shannOnW!
SickBunny at 2007-6-29 3:07:21 > top of Java-index,Archived Forums,New To Java Technology Archive...