How to cast an Object to an int

Viewed 781027

How can I cast an Object to an int in java?

20 Answers
so divide1=me.getValue()/2;

int divide1 = (Integer) me.getValue()/2;

We could cast an object to Integer in Java using below code.

int value = Integer.parseInt(object.toString());

Finally, the best implementation for your specification was found.

public int tellMyNumber(Object any) {
    return 42;
}
Related