I am returning either boolean, string or integer value as an Object in Java. How to identify type of value once returned?

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.

1 Answer

answered by
selected by
0 votes
Best answer

You can use object.getClass() to get data type:

ArrayList<Object> list = ...;
for (Object o : list) {
    if (o.getClass().equals(Integer.class)) {
    else if (o.getClass().equals(String.class)) {