b3ta.com board
You are not logged in. Login or Signup
Home » Messageboard » XXX » Message 3066424 (Thread)

# not those vectors
in java vectors are dynamic data structures
(, Tue 20 Apr 2004, 1:27, archived)
# sounds similar to
std vector in c++, what is the question?
(, Tue 20 Apr 2004, 1:29, archived)
#
i) in your driver class create a new Vector, and use it to store the two instances of the Politican calss you created in quesation 1


the two instances are called politician1 and politician2
i tried using myVector.add(politician1); but it errored and so did myVector.addElement(blah);
(, Tue 20 Apr 2004, 1:32, archived)
#
have you called new on the vector?

Vector v;
v = new Vector();
v.addElement(politician1);
(, Tue 20 Apr 2004, 1:37, archived)
# yeah
Vector myVector = new Vector();
myVector.addElement(politician1);
(, Tue 20 Apr 2004, 1:39, archived)
# was the error message helpful?
(, Tue 20 Apr 2004, 1:44, archived)
# as with all java errors...
no
(, Tue 20 Apr 2004, 1:53, archived)
# sommit like dis?
Vector myVector = new Vector();
myVector.add(politican1);
myVector.add(politican2);

inside the Vector, they are stored as nameless Objects to get them back, u need to use casting, and assign to new
variables

Politican pol1, pol2;
pol1 = (Politican)myVector.get(0);
pol2 = (Politican)myVector.get(1);
(, Tue 20 Apr 2004, 1:45, archived)
# oh...
and u got 'import java.util.Vector;' first thing at the top of ur class file right...
(, Tue 20 Apr 2004, 1:46, archived)
# no
i stuck "import java.util.*" so it imports everything

i'll add .Vector and see if that helps
(, Tue 20 Apr 2004, 1:48, archived)
# ah
indeed it has fixed my problem, thanks :D
(, Tue 20 Apr 2004, 1:49, archived)
# tis cool
but .*; should av worked ... maybe was a typo there?

::heads back to evil Java dissertation::
(, Tue 20 Apr 2004, 1:53, archived)
# me knows a bit
on msn/aim/4rthur,
same username

/relurks
(, Tue 20 Apr 2004, 1:29, archived)
# look up at reply ^^
(, Tue 20 Apr 2004, 1:33, archived)