Java tutorial
//package com.java2s; import java.util.Hashtable; import java.util.Vector; import java.io.IOException; public class Main { public static final String TAG_HASHTABLE = "Hashtable"; public static final String TAG_VECTOR = "Vector"; public static final String TAG_ARRAY = "ArrayList"; public static final String TAG_STRING = "String"; public static final String TAG_INTEGER = "Integer"; public static final String TAG_DOUBLE = "Double"; public static final String TAG_FLOAT = "Float"; public static final String TAG_BOOLEAN = "Boolean"; public static final String TAG_SHORT = "Short"; public static final String TAG_LONG = "Long"; public static final String TAG_CHARACTER = "Character"; public static final String TAG_BYTE = "Byte"; public static final String TAG_NULL = "nulltype"; protected static String getObjectType(Object object) throws IOException { String tagName; if (object == null) { tagName = TAG_NULL; } else if (object instanceof String) { tagName = TAG_STRING; } else if (object instanceof Integer) { tagName = TAG_INTEGER; } else if (object instanceof Character) { tagName = TAG_CHARACTER; } else if (object instanceof Double) { tagName = TAG_DOUBLE; } else if (object instanceof Float) { tagName = TAG_FLOAT; } else if (object instanceof Boolean) { tagName = TAG_BOOLEAN; } else if (object instanceof Byte) { tagName = TAG_BYTE; } else if (object instanceof Short) { tagName = TAG_SHORT; } else if (object instanceof Long) { tagName = TAG_LONG; } else if (object instanceof Hashtable) { tagName = TAG_HASHTABLE; } else if (object instanceof Vector) { tagName = TAG_VECTOR; } else if (object instanceof Object[]) { tagName = TAG_ARRAY; } else { // TODO somehow encode it or do something else?? throw new IOException("unknown class: " + object.getClass() + " for object: " + object); } return tagName; } }