How to Convert an Object to a Long Primitive in Java

104 15
    • 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();

Subscribe to our newsletter
Sign up here to get the latest news, updates and special offers delivered directly to your inbox.
You can unsubscribe at any time

Leave A Reply

Your email address will not be published.