469,353 Members | 2,053 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,353 developers. It's quick & easy.

How to convert Object to Vector

hi,

I have converted vector to object. How can I convert Object into Vector.

My code look like this,

Expand|Select|Wrap|Line Numbers
  1.  
  2. Vector column=new Vector();
  3. column.add("one");
  4. column.add("two");
  5. Object ob=column;
  6. //here i am calling a method
  7. mymethod(ob)
  8. {
  9. // how can i convert ob Object to Vector 
  10. }
  11.  
Thanks in advance.
Jul 24 '08 #1
5 15637
r035198x
13,262 8TB
Typecasting.
Expand|Select|Wrap|Line Numbers
  1. Vector v = (Vector)ob;
Your code doesn't look all that clean though.
Why are you changing the Vector to the object in the first place? Also note that Vectors are old. Rather use ArrayList. It's probably what you want to use there.
Jul 24 '08 #2
Brosert
57
Depends what you mean convert....
Given that the object (ob) was originally a Vector, you can cast it to a Vector.....

eg to print the first object
Expand|Select|Wrap|Line Numbers
  1. prinln(((Vector)ob).get(0).toString());
  2.  
Jul 24 '08 #3
hi,

I have to receive ob as String(with the same vector value again i have to convert Vector here). Like

void mymethod(String s)
{
Vector v = (Vector)s ; // like this
}

How can i do this.
Jul 24 '08 #4
hi,

Is there any way to convert Vector to String?.

Thanks in advance.
Jul 24 '08 #5
r035198x
13,262 8TB
hi,

Is there any way to convert Vector to String?.

Thanks in advance.
In your code above, you are trying convert a String to a Vector not a Vector to a String.
The best thing here is for you to explain the problem you are trying to solve. All the type juggling you are tring to do can be avoided by designing your solution properly. Tell us your problem definition.
Jul 24 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Max | last post: by
2 posts views Thread by Nikolay Petrov | last post: by
5 posts views Thread by tienlx | last post: by
reply views Thread by bacsumu | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.