I have a String like \"09a\" and I need a method to confirm if the text is hexadecimal. The code I\'ve posted does something similar, it verifies that a string is a decimal
Used this in my own code to check if string is a MAC address
boolean isHex = mac_addr.matches("^[0-9a-fA-F]+$");
My beef with the other answers provided in this thread is that if the String's length is large, it would throw an exception as well. Therefore, not very useful if you are testing if a MAC address consist of valid hexadecimals.
Don't be terrified of using regex!