BUGGER IT ALL!!
Dont suppose any Java programmers know how to use Vectors? if so HEEEEELP ME!!
( ,
Tue 20 Apr 2004, 1:23,
archived)
but...
you're the moon lord... you're supposed to know EVERYTHING
my world has collapsed.
( ,
Tue 20 Apr 2004, 1:24,
archived)
my world has collapsed.
everything about moons
not java, java is evil, its like the Anti-Moon
( ,
Tue 20 Apr 2004, 1:25,
archived)
Urm ... read the API
They're just a container class.
You can add elements ...
You can remove elements ...
You can get the Nth element ...
Think of them as resizable arrays with silly (and non orthogonal) API.
Remember to get an enumeration from them if you need to process all the elements in a non-atomic manner (ie, to make callbacks or whatnot).
Actually the semantics of Vector suck lots and some of the Java 2 list classes/interfaces are a far better bet.
The only thing I'd really warn you against is using the seraching functionality (findElement() I think). It uses the equals() method to determine a match and it calls it on the array element, not the thing you passed in. This can lead to some unexpected results (always do searching manually, it's almost always more efficient).
EDIT: Nahh, it's indexOf() and contains() that suck like that.
( ,
Tue 20 Apr 2004, 2:08,
archived)
You can add elements ...
You can remove elements ...
You can get the Nth element ...
Think of them as resizable arrays with silly (and non orthogonal) API.
Remember to get an enumeration from them if you need to process all the elements in a non-atomic manner (ie, to make callbacks or whatnot).
Actually the semantics of Vector suck lots and some of the Java 2 list classes/interfaces are a far better bet.
The only thing I'd really warn you against is using the seraching functionality (findElement() I think). It uses the equals() method to determine a match and it calls it on the array element, not the thing you passed in. This can lead to some unexpected results (always do searching manually, it's almost always more efficient).
EDIT: Nahh, it's indexOf() and contains() that suck like that.
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)
the two instances are called politician1 and politician2
i tried using myVector.add(politician1); but it errored and so did myVector.addElement(blah);
have you called new on the vector?
Vector v;
v = new Vector();
v.addElement(politician1);
( ,
Tue 20 Apr 2004, 1:37,
archived)
Vector v;
v = new Vector();
v.addElement(politician1);
yeah
Vector myVector = new Vector();
myVector.addElement(politician1);
( ,
Tue 20 Apr 2004, 1:39,
archived)
myVector.addElement(politician1);
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)
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);
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)
i'll add .Vector and see if that helps