public class Test { public static boolean isHex(String str) { boolean isHexFlg = true; int i = 0; char c; for (i = 0; i < str.length(); i++) { c = str.charAt(i); if ( !( ( ( c >= '0' ) && ( c <= '9' ) ) || ( ( c >= 'A' ) && ( c <= 'F' ) ) || ( c >= 'a' ) && ( c <= 'f' ) ) ) { isHexFlg = false; } } return isHexFlg; } /** * @param args */ public static void main(String[] args) { boolean b = false; String str = "11111112222222aadd1232"; b = isHex(str); if (b) { System.out.println(str + "是十六进制数"); } else { System.out.println(str +"不是十六进制数"); } } }