Java Utililty Methods Object Create

List of utility methods to do Object Create

Description

The list of methods to do Object Create are organized into topic(s).

Method

Tas(Object obj)
as
T result;
try {
    result = obj == null ? null : (T) obj;
} catch (ClassCastException cce) {
    result = null;
return result;
Tas(Object value, Class c)
as
if (value == null)
    return null;
if (c.isAssignableFrom(value.getClass()))
    return c.cast(value);
return null;
Tas(Object value, Class type)
Returns the given value cast to the given type if it is an instance of it, null otherwise
if (type.isInstance(value)) {
    return type.cast(value);
return null;
Boolean[]toObject(boolean[] array)
to Object
if (array == null)
    return null;
if (array.length == 0) {
    return EMPTY_BOOLEAN_OBJECT_ARRAY;
Boolean[] result = new Boolean[array.length];
for (int i = 0; i < array.length; i++) {
    result[i] = Boolean.valueOf(array[i]);
...
Byte[]toObject(byte[] array)
to Object
if (array == null) {
    return null;
} else if (array.length == 0) {
    return EmptyByteObjectArray;
final Byte[] result = new Byte[array.length];
for (int i = 0; i < array.length; i++) {
    result[i] = Byte.valueOf(array[i]);
...
Byte[]toObject(byte[] byteArray)
Converts an array of primitive bytes to objects.
if (byteArray == null) {
    return null;
Byte[] box = new Byte[byteArray.length];
for (int i = 0; i < box.length; i++) {
    box[i] = byteArray[i];
return box;
...
Byte[]toObject(byte[] primitiveArray)
to Object
Byte[] objectArray = new Byte[primitiveArray.length];
for (int i = 0; i < primitiveArray.length; i++)
    objectArray[i] = primitiveArray[i];
return objectArray;
ObjecttoObject(Class clazz, String value)
This method parses the given value into the specified primitive or wrapper class.
if (Boolean.TYPE == clazz)
    return Boolean.parseBoolean(value);
if (Byte.TYPE == clazz)
    return Byte.parseByte(value);
if (Short.TYPE == clazz)
    return Short.parseShort(value);
if (Integer.TYPE == clazz)
    return Integer.parseInt(value);
...
Double[]toObject(double[] a)
Converts a double array into a Double (Object) array.
Double[] a2 = new Double[a.length];
for (int i = 0; i < a.length; i++) {
    a2[i] = a[i];
return a2;
IntegertoObject(final int i)
to Object
return Integer.valueOf(i);