Thread View: comp.lang.java
3 messages
3 total messages
Started by Nelson Tong
Tue, 03 Jun 2003 08:53
Vector example!!
Author: Nelson Tong
Date: Tue, 03 Jun 2003 08:53
Date: Tue, 03 Jun 2003 08:53
5 lines
1607 bytes
1607 bytes
I have been look at some book and from the net about Vector, but still not very understand how the "Vector" work!! Can anyone send me a example of Vector to the following email address please!! nelsontong1972@yahoo.com.au
Re: Vector example!!
Author: Erwin Moller
Date: Wed, 04 Jun 2003 10:01
Date: Wed, 04 Jun 2003 10:01
21 lines
1746 bytes
1746 bytes
Nelson Tong wrote: > I have been look at some book and from the net about Vector, but still > not very understand how the "Vector" work!! Can anyone send me a > example of Vector to the following email address please!! > > nelsontong1972@yahoo.com.au Hi Nelson, When I read a posting like this, I always think: "I guess somebody mailed him already." and I don't help you out futher. I think you would be better of just waiting for a response in the group you posted in. In that way usenet has also use for others.. Regards, Erwin
Re: Vector example!!
Author: Paul Kossler
Date: Wed, 04 Jun 2003 14:29
Date: Wed, 04 Jun 2003 14:29
41 lines
2564 bytes
2564 bytes
Nelson Tong <nelsontong1972@iprimus.com.au> wrote in message news:<3EDC6206.88E93CDE@iprimus.com.au>...
> I have been look at some book and from the net about Vector, but still
> not very understand how the "Vector" work!! Can anyone send me a
> example of Vector to the following email address please!!
>
> nelsontong1972@yahoo.com.au
A Vector is a simple expandable stack like array which has
synchronized accessor methods(thread safe, but slows you down some if
you do not need them, so the current best practice is to use ArrayList
if you do not need the synchonization)
Check out Sun's official documentation for more information:
http://java.sun.com/j2se/1.4.2/docs/api/java/util/Vector.html
Here is a simple explained use of a Vector
Vector v1 = new Vector();
v1.add("First Element"); //adds a string to the list, can be any
Object
v1.add("Second Element"); //add another string
v1.add(new Integer(5)); // add an integer in the Integer primitive
wrapper
/*with some elements in the Vector you can check for presence of
elements, or
get them at their index(like an array[]), get an itterator to traverse
the list, clear the list, etc.
*/
int lengthOfVector = v1.size();
boolean bVectorContainsElement = v1.contains("First Element"); // true
boolean bFalse = v1.contains(5); // exception needs to be an object
and will not compile
boolean bTrue = v1.contains(Integer(5));
String elementOne = (String)v1.get(0);
// clear the list
v1.clear();
Have fun,
Paul Kossler
Sr.Software Engineer
CACI
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads