Here you can find the source of toCharacter(Object o)
public static Character toCharacter(Object o)
//package com.java2s; //License from project: LGPL public class Main { public static Character toCharacter(Object o) { if (o == null) return null; if (o.getClass() == Character.class) return (Character) o; if (o.getClass() == Boolean.class) return booleanToChar((Boolean) o); if (o.getClass() == Byte.class) return (char) ((Byte) o).byteValue(); if (o.getClass() == Short.class) return shortToCharacter((Short) o); if (o.getClass() == Integer.class) return intToCharacter((Integer) o); if (o.getClass() == Long.class) return longToCharacter((Long) o); if (o.getClass() == Float.class) return floatToCharacter((Float) o); if (o.getClass() == Double.class) return doubleToCharacter((Double) o); if (o.getClass() == String.class) return stringToCharacter((String) o); return null; }/*from w w w .j a v a2 s .com*/ public static char booleanToChar(boolean b) { return b ? (char) 1 : 0; } public static Character shortToCharacter(short h) { if (h >= Character.MIN_VALUE && h <= Character.MAX_VALUE) { return (char) h; } return null; } public static Character intToCharacter(int i) { if (i >= Character.MIN_VALUE && i <= Character.MAX_VALUE) { return (char) i; } return null; } public static Character longToCharacter(long l) { if (l >= Character.MIN_VALUE && l <= Character.MAX_VALUE) { return (char) l; } return null; } public static Character floatToCharacter(float f) { if (f >= Character.MIN_VALUE && f <= Character.MAX_VALUE) { return (char) f; } return null; } public static Character doubleToCharacter(double d) { if (d >= Character.MIN_VALUE && d <= Character.MAX_VALUE) { return (char) d; } return null; } public static Character stringToCharacter(String s) { if (s == null || s.length() != 1) return null; try { return s.charAt(0); } catch (IndexOutOfBoundsException e) { return null; } } }