Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2005

Tip: Looking for answers? Try searching our database.

initialize a vector with data

Thread view: 
Jacques Chaurette - 15 Oct 2005 00:56 GMT
Sorry for this basic question but I cannot find anywhere how to initialed a vector with data.

Thanks.

Jacques
Roedy Green - 15 Oct 2005 02:34 GMT
>Sorry for this basic question but I cannot find anywhere how to initialed a vector with data.

Whenever you need an introduction to something in Java, one place you
can usually get started is the Java glossary.  It will give you an
overview and point you to more detailed information, and usually give
you a brief code sample of the basic operations.
http://mindprod.com/jgloss/jgloss.html

Just look up the word, in this case Vector.

http://mindprod.com/jgloss/vector.html

It will suggest you try ArrayList instead.

Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.

Jacques Chaurette - 15 Oct 2005 12:40 GMT
Thanks.

>>Sorry for this basic question but I cannot find anywhere how to initialed
>>a vector with data.
[quoted text clipped - 10 lines]
>
> It will suggest you try ArrayList instead.
Thomas Weidenfeller - 17 Oct 2005 09:36 GMT
> Sorry for this basic question but I cannot find anywhere how to
> initialed a vector with data.

In general, consider using ArrayList instead of Vector. It basically
does the same, but ArrayList is in general a faster.

Regarding the initialization of a Vector (or ArrayList):

Since Java 1.2:

    Vector v = new Vector(Arrays.asList(<array-of-elements>));
or
    Vector v = new Vector();
    v.addAll(Arrays.asList(<array-of-elements>));

or a simple loop with calls to add().

In Java 1.5 you an also do (the stuff above also works):

    Vector v = new Vector();
    Collections.addAll(v, <array-or-varlist-of-elements>);

The 1.5 documentation claims this can be faster than Arrays.asList(). In
1.5. Arrays.asList() also allows a variable length list as argument.

/Thomas
Signature

The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.