Tuesday, August 4, 2015

[Java] Check if string is an integer

Sample code to check if String is Integer.



protected static boolean isInteger(String string) {
  try { 
  Integer.parseInt(string); 
  } catch(NumberFormatException e) { 
   return false; 
  } catch(NullPointerException e) {
   return false;
 }
   return true;
}



No comments:

Post a Comment