944,168 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 2757
  • Java RSS
Sep 26th, 2005
0

Vectors Versus Arrays

Expand Post »
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!!
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kbradley is offline Offline
7 posts
since Sep 2005
Sep 26th, 2005
0

Re: Vectors Versus Arrays

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).
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Sep 26th, 2005
0

Re: Vectors Versus Arrays

Vectors are evil, look up the ArrayList if you want an array that grows as needed.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Sep 26th, 2005
0

Re: Vectors Versus Arrays

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!!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kbradley is offline Offline
7 posts
since Sep 2005
Sep 26th, 2005
0

Re: Vectors Versus Arrays

Java Syntax (Toggle Plain Text)
  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.
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
Sep 27th, 2005
0

Re: Vectors Versus Arrays

How can someone understand Vector but not ArrayList?
They have the exact same interface...
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Sep 27th, 2005
0

Re: Vectors Versus Arrays

Hi everyone,

Quote 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
*****************************************************
Reputation Points: 25
Solved Threads: 10
Practically a Master Poster
freesoft_2000 is offline Offline
623 posts
since Jun 2004
Sep 27th, 2005
0

Re: Vectors Versus Arrays

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.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Mr
Next Thread in Java Forum Timeline: Display Value in JcomboBox





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC