Welcome to the Question and Answer site for Software Testing Professionals

You can get your queries resolved from Software Testing Professionals.

Ask a Question

Get answers and give answers to questions from other members.

View All Questions

Get votes and earn points to build your reputation in community.

View Hot Questions

0
how to find data type of a value returned using an Object in Java

Solved 1 Answers 32 Views Programming
0 1
I am returning either boolean, string or integer value as an Object in Java. How to identify type of value once returned?

1 Answer

0
Best answer
0

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

ArrayList<Object> list = ...;
for (Object o : list) {
    if (o.getClass().equals(Integer.class)) {
        handleInt((int)o);
    }
    else if (o.getClass().equals(String.class)) {
        handleString((String)o);
    }
    ...
}
answered Feb 10, 2016 by anonymous
selected Mar 7, 2017 by stbadmin

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.

We have resolved 1.2k+ Software Testing queries!

Software Testing Board Weekly update

We will send you handpicked questions that you would love to answer.

View previous campaigns.

Top Contributors

...