Allocating an object into an array in Java

Possible duplicate:
How to convert an array of objects to a string array in Java

I get the object and translate it into a String array as follows:

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 a better and cleaner way to do this?

+1
source share
1 answer

Why not direct casting?

String values[] = (String[])request.getSession().getAttribute("userList");
+5
source

All Articles