JAVA에서 String이 '숫자'로만 이루어져 있는지 체크


JAVA에서 String이 '숫자'로만 이루어져 있는지 체크

출처 : http://stackoverflow.com/questions/1102891/how-to-check-if-a-string-is-a-numeric-type-in-java How to check if a String is a numeric type in Java How would you check if a String was a number before parsing it? stackoverflow.com 1. Exception 사용 public static boolean isNumeric(String str) { try { double d = Double.parseDouble(str); } catch(NumberFormatException nfe) { return false; } return true; } 2. 정규식 사용 public static boolean isNumeric(String str) { return str.matches("-?\\d+(\\.\\d+)?"); ...


#IT·컴퓨터

원문링크 : JAVA에서 String이 '숫자'로만 이루어져 있는지 체크