How to Convert an Object to a Long Primitive in Java
- 1). Get the String representation of your object:
// Assuming object named "obj".
final String theString = obj.toString(); - 2). Create a Long object instance given the string representation:
final Long theLongObj = new Long(theString); - 3). Get the long (primitive) value from your Long object:
final long theLongPrim = theLongObj.longValue();