Convert String to Character - Java java.lang

Java examples for java.lang:char

Description

Convert String to Character

Demo Code


//package com.java2s;

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

    public static Character getChar(String value, Character defaultValue) {
        try {
            return Character.valueOf(value.charAt(0));
        } catch (Exception ex) {
            return defaultValue;
        }
    }

    public static Character getChar(String value) {
        return getChar(value, null);
    }
}

Related Tutorials