vendredi 9 septembre 2016

How do I compare strings representation of integers?

I was wondering how I could use an if statement as if they were integers for strings?

/**
 * 
 * @param token
 * @return true if parameter is the String representation of an integer
 * between 0 and 255 (including 0 and 255), false otherwise.
 * Strings "0", "1", "2" .... "254", "255" are valid.
 * Padded Strings (such as "00000000153") are also valid 
 */


public static boolean isValidElement(String token) {
    if (token=> 0 || token <=255)
      return true;
    return false; 
}

This is what I currently have in mind at the moment but obviously it won't work for strings.

Aucun commentaire:

Enregistrer un commentaire