How to Access a vector inside another vector

Discussions

Web tier: servlets, JSP, Web frameworks: How to Access a vector inside another vector

  1. How to Access a vector inside another vector (2 messages)

    hello!

    I wonder how can one reach an element inside a vector, which it self is an element of another vector.
    Ex:
                    Vector guide = new Vector();
    Vector category1 = new Vector();
    category1.addElement("item1");
    guide.addElement(category1);
    I want to reach “item1” in “category 1” directly from vector “guide”.

    Tanks in advance

    Threaded Messages (2)

  2. try this[ Go to top ]

    Vector guide = new Vector();
    Vector category1 = new Vector();
    category1.addElement("item1");
    guide.addElement(category1);
    System.out.println("---"+( (Vector) (guide.get(0)) ).get(0));
  3. I think this should've been posted on a Java forum, not a Web Tier forum, but...

    // your stuff
    Vector guide = new Vector();
    Vector category1 = new Vector();
    category1.addElement("item1");
    guide.addElement(category1);

    // the "answer"
    Vector innerVector = (Vector) guide.get(0); // get the first object in the vector
    String item = (String) innerVector.get(0); // get the first object in the vector
    System.out.println("item: " + item); // prints "item: item1"