is string a hexidecimal number - Android java.lang

Android examples for java.lang:Integer

Description

is string a hexidecimal number

Demo Code

import android.content.Context;
import android.content.res.AssetManager;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class Main{

    /**/*from  w  ww.  ja v a  2  s.c  o m*/
     * is s a hexidecimal number
     * @param s
     * @return true if 0x<digits>
     */
    public static boolean isHexNumber(String s) {
        if ((s.charAt(0) != '0') || (s.charAt(1) != 'x')) {
            return false;
        }
        for (int ich = 2; ich < s.length(); ich++) {
            if (!Character.isDigit(s.charAt(ich))) {
                return false;
            }
        }
        return true;
    }

}

Related Tutorials