how do i create a vector within a vector ?

L

learningjava

I need to create an array A of vectors V.
each Vector V contains three elements, Object a, Vector E.
Vector E contains two or more elements, Object 1, Object 2 ....

Can you give me a framework in java to do this?
a test class for this will help too.

Thanks,

gk
 
S

Sudsy

learningjava said:
I need to create an array A of vectors V.
each Vector V contains three elements, Object a, Vector E.

(that's only two...)
Vector E contains two or more elements, Object 1, Object 2 ....

Can you give me a framework in java to do this?

No! (It's already there for you)
a test class for this will help too.

I'm sure it would, but that's missing the point. What you don't
seem to grasp is that a Vector IS an Object.
A Vector is also a collection of Objects. As such, it can
contain anything else which is an Object, including other
Vectors.
IOW, Vectors can contain Vectors which contain Vectors, etc
ad nauseum.
What you need to be doing is analyzing the problem by reducing
to the LCD. Since Arrays and Vectors are Objects at heart, try
rethinking in terms of Objects without regard to class.
Once you've done that then you can start looking at the
instanceof operator and determine how you can use it in this
particular problem scenario.
 
P

Paul Lutus

learningjava said:
I need to create an array A of vectors V.
each Vector V contains three elements, Object a, Vector E.
Vector E contains two or more elements, Object 1, Object 2 ....

Can you give me a framework in java to do this?

No, but you can complete your own assignment.
a test class for this will help too.

Okay, then write it. Post your code when you have specific questions.

Vector a = new Vector();

Vector b = new Vector();

Vector c = new Vector();

a.add(b);

b.add(c);

Now Vector a has Vector b as a member, and Vector b has Vector c as a
member. That's the basic idea.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top