1

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
  • 5,950
  • 11
  • 49
  • 69

1 Answers1

5

Why not directly casting?

String values[] = (String[])request.getSession().getAttribute("userList");
Juvanis
  • 25,366
  • 5
  • 65
  • 85