Casting Vector to String
I am getting a classcastexception error when I try to cast a vector to a string, which I thought was possible.
Can anyone assist me please?
ResultSet rsFaculty = faculty.getNewFaculty();
Vector v = new Vector();
Vector row = new Vector();
int vsize = v.size();
int choice = (int)(Math.random()*vsize);
String StringName = (String) v.elementAt(2);
You cannot cast a Vector to a String. It is nothing like a string. Even though you have Strings in it, the Vector itself is completely different. You could call the toString() method of Vector, but that would likely only give you the memory address of the object and nothing else. To get to your strings you need to dereference twice. Once for the first Vector and again for the strings inside.
Your code has typo's and is a little confusing. What are you trying to accomplish in detail?
Thanks for your reply Nemi.
I got it working earlier.