Parse String to Byte value with default value - Java java.lang

Java examples for java.lang:String Parse

Description

Parse String to Byte value with default value

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        String value = "java2s.com";
        System.out.println(getByte(value));
    }// w ww . j a v  a  2  s .com

    public static Byte getByte(String value, Byte defaultValue) {
        try {
            return Byte.valueOf(value);
        } catch (Exception ex) {
            return defaultValue;
        }
    }

    public static Byte getByte(String value) {
        return getByte(value, null);
    }
}

Related Tutorials