Vectors Versus Arrays

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Sep 2005
Posts: 7
Reputation: kbradley is an unknown quantity at this point 
Solved Threads: 0
kbradley kbradley is offline Offline
Newbie Poster

Vectors Versus Arrays

 
0
  #1
Sep 26th, 2005
I am designing a Rinex file reader class in Java and this is my first project in Java. I need to store data into an array or vector. I am reading the data from the file related to the time the data occurs. At first I tried to use an array but I do not know the size of the array ahead of time. Is there anyway to make an array change size as it grows in a loop? For example in Matlab you could initialize the array to be an array of zeros. Or do I have to use vectors to do this? I also have this problem with a 3D array that I was creating. How would I use vectors to create a 3D array? Thanks!!
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Vectors Versus Arrays

 
0
  #2
Sep 26th, 2005
No, you cannot change the size of an array.
Use an ArrayList instead, not a Vector. Vector has notoriously poor performance, and should only be used when an ArrayList cannot provide the functionality needed while a Vector can (by the time you know when that is you know what it is).
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,789
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 746
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Vectors Versus Arrays

 
0
  #3
Sep 26th, 2005
Vectors are evil, look up the ArrayList if you want an array that grows as needed.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 7
Reputation: kbradley is an unknown quantity at this point 
Solved Threads: 0
kbradley kbradley is offline Offline
Newbie Poster

Re: Vectors Versus Arrays

 
0
  #4
Sep 26th, 2005
Thanks for your help. I have tried looking up arraylist on the Java Api site but I am having a little trouble understanding what it is and what syntax is required to make it work. Can anyone give me a better explanation than what is on Sun's page? Thanks!!
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: Vectors Versus Arrays

 
0
  #5
Sep 26th, 2005
  1. import java.util.*;
  2.  
  3. class Test
  4. {
  5. public static void main(String[] args)
  6. {
  7. ArrayList al = new ArrayList();
  8. al.add("one");
  9. al.add("two");
  10. }
  11. }

Notice how there's no set size anywhere.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Vectors Versus Arrays

 
0
  #6
Sep 27th, 2005
How can someone understand Vector but not ArrayList?
They have the exact same interface...
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 609
Reputation: freesoft_2000 is an unknown quantity at this point 
Solved Threads: 8
freesoft_2000 freesoft_2000 is offline Offline
Practically a Master Poster

Re: Vectors Versus Arrays

 
0
  #7
Sep 27th, 2005
Hi everyone,

Originally Posted by Narue
Vectors are evil, look up the ArrayList if you want an array that grows as needed.
Narue what makes you say that vectors are evil?

Richard West
*****************************************************
Microsoft uses "One World, One Web, One Program" as a slogan.
Doesn’t that sound like "Ein Volk, Ein Reich, Ein Führer" to you, too?
— Eric S. Raymond

Tell me what type of software do you like and what would you pay for it

http://www.daniweb.com/techtalkforums/thread19660.html
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Vectors Versus Arrays

 
0
  #8
Sep 27th, 2005
The same reason I say they should be deprecated (or better yet, banned to the 7th circle of computer hell)
They're slow, have a confusing API (with many duplicate functions) because of the way they were retrofitted to support the List interface, are generally not needed (and when you could have a case for them there are still better alternatives), etc. etc.

Basically they're among the dinosaurs of Java, together with StringTokenizer and some other very old classes that now have better alternatives but have been kept on because someone forgot to remove them.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC