How to convert Object to Vector

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • deepthisoft
    New Member
    • Jul 2007
    • 27

    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,

    [code=java]

    Vector column=new Vector();
    column.add("one ");
    column.add("two ");
    Object ob=column;
    //here i am calling a method
    mymethod(ob)
    {
    // how can i convert ob Object to Vector
    }
    [/code]
    Thanks in advance.
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Typecasting.
    [CODE=java]
    Vector v = (Vector)ob;[/CODE]

    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.

    Comment

    • Brosert
      New Member
      • Jul 2008
      • 57

      #3
      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
      Code:
      prinln(((Vector)ob).get(0).toString());

      Comment

      • deepthisoft
        New Member
        • Jul 2007
        • 27

        #4
        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.

        Comment

        • deepthisoft
          New Member
          • Jul 2007
          • 27

          #5
          hi,

          Is there any way to convert Vector to String?.

          Thanks in advance.

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Originally posted by deepthisoft
            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.

            Comment

            Working...