🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.java
Article #374

Re: Vector example!!

#374
From: Paul Kossler
Date: Wed, 04 Jun 2003 14:29
41 lines
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
Technical Details
Message-ID: <4778f1e0.0306040629.61bedd73@posting.google.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!postnews1.google.com!not-for-mail
References: <3EDC6206.88E93CDE@iprimus.com.au>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10d6db,723278ef1a06e984
X-Google-Attributes: gid10d6db,public
X-Google-Thread: f5d71,723278ef1a06e984
X-Google-Attributes: gidf5d71,public
X-Google-Thread: 113ae9,723278ef1a06e984
X-Google-Attributes: gid113ae9,public
X-Google-ArrivalTime: 2003-06-04 07:29:02 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!postnews1.google.com!not-for-mail
From: paulkossler@yahoo.com (Paul Kossler)
Newsgroups: comp.lang.java,aus.computers.java,comp.lang.java.help
Subject: Re: Vector example!!
Date: 4 Jun 2003 07:29:01 -0700
Organization: http://groups.google.com/
Lines: 41
Message-ID: <4778f1e0.0306040629.61bedd73@posting.google.com>
References: <3EDC6206.88E93CDE@iprimus.com.au>
NNTP-Posting-Host: 192.171.10.24
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-Trace: posting.google.com 1054736942 16893 127.0.0.1 (4 Jun 2003 14:29:02 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: 4 Jun 2003 14:29:02 GMT