Hello.

I would like to ask some suggestions to the community.

In Arrays, we can implement a 2D array like:

String[][] testString = new String[][] {
    {"1", "2", "6"},
    {"4", "5", "3"}
  };

How can I implement this in Vector? Or is that even possible?
I was doing it in Vector<Vector<>> manner but (obviously) it will not work. ^^;;

I want to include a code something like

...
if(variable.elementAt(i).elementAt(j).equals(something))

Sorry for the confusion.

Recommended Answers

No so obviously. There's absolutely no reason why you can't have a Vector of Vectors. Just remember that you have to populate the outer Vector with new inner Vector(s).

Vector<Vector<String>> v = new Vector<Vector<String>>();
v.add(new Vector<String>());
v.elementAt(0).elementAt(0) ...
Jump to Post

All 3 Replies

That code works for me. Can you post the code that didn't work.

No so obviously. There's absolutely no reason why you can't have a Vector of Vectors. Just remember that you have to populate the outer Vector with new inner Vector(s).

Vector<Vector<String>> v = new Vector<Vector<String>>();
v.add(new Vector<String>());
v.elementAt(0).elementAt(0) ...

Yeah it works perfectly... This is allowed.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.