2

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?

Community
  • 1
  • 1
Rafay
  • 6,108
  • 11
  • 51
  • 71

1 Answers1

6

Why not directly casting?

String values[] = (String[])request.getSession().getAttribute("userList");
Juvanis
  • 25,802
  • 5
  • 69
  • 87