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.

appending to the end of array

Thread view: 
azzamqazi@gmail.com - 02 Oct 2005 17:32 GMT
hi guys,
 i am having a problem and was thinking if someone can help me. ok
here it goes. How do i append to the end of an array?? I mean if i have
an array of strings how do i append a new string at the end of the
array in another method. Thanks guys :)

PS i think it might have to do something wit stacks but not sure :)
Kenneth P. Turvey - 02 Oct 2005 23:35 GMT
On Sun, 02 Oct 2005 09:32:29 -0700, azzamqazi wrote:

> hi guys,
>   i am having a problem and was thinking if someone can help me. ok
> here it goes. How do i append to the end of an array?? I mean if i
> have an array of strings how do i append a new string at the end of
> the array in another method. Thanks guys :)

There is no way to increase the size of an array.  You have to create a
new array however big you need it and then copy the old array into it.  

If this is really what you want to do, of course.

If you you are regularly doing this on large arrays you will end up with
a very poorly performing implementation.  You should look at using a
LinkedList or ArrayList.  These are implementations of the List
interface of the collections API.  This is really what you probably
want.

> PS i think it might have to do something wit stacks but not sure :)

Hmm.  Maybe in how you would implement one.  Take a look at Stack too.  

- --
Kenneth P. Turvey <kt-usenet@squeakydolphin.com>
http://kt.squeakydolphin.com (not much there yet)
Jabber IM: kpturvey@jabber.org
Phone: (314) 255-2199
Roedy Green - 02 Oct 2005 23:49 GMT
>  i am having a problem and was thinking if someone can help me. ok
>here it goes. How do i append to the end of an array?? I mean if i have
>an array of strings how do i append a new string at the end of the
>array in another method. Thanks guys :)

use an ArrayList

See http://mindprod.com/jgloss/arraylist.html
Signature

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



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.