Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Casting Object to Array in Java [duplicate]

Possible Duplicate:
How to convert object array to string array in Java

I am receiving an Object and casting it into a String array like this:

Object values[] = (Object[])request.getSession().getAttribute("userList");
String[] tmp = new String[values.length];
for(int i = 0; i < tmp.length; ++i) {
     tmp[i] = (String) values[i];
     out.println(tmp[i]);
}

Is there any better and cleaner way to do this?

like image 919
Rafay Avatar asked Apr 19 '26 12:04

Rafay


1 Answers

Why not directly casting?

String values[] = (String[])request.getSession().getAttribute("userList");
like image 142
Juvanis Avatar answered Apr 22 '26 02:04

Juvanis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!