| | |
Vectors Versus Arrays
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Sep 2005
Posts: 7
Reputation:
Solved Threads: 0
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!!
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).
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.
•
•
Join Date: Jun 2004
Posts: 2,108
Reputation:
Solved Threads: 18
Java Syntax (Toggle Plain Text)
import java.util.*; class Test { public static void main(String[] args) { ArrayList al = new ArrayList(); al.add("one"); al.add("two"); } }
Notice how there's no set size anywhere.
•
•
Join Date: Jun 2004
Posts: 609
Reputation:
Solved Threads: 8
Hi everyone,
Narue what makes you say that vectors are evil?
Richard West
*****************************************************
•
•
•
•
Originally Posted by Narue
Vectors are evil, look up the ArrayList if you want an array that grows as needed.
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
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
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.

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.
![]() |
Similar Threads
- array help plz! (C++)
- directions (C++)
Other Threads in the Java Forum
- Previous Thread: Mr
- Next Thread: Display Value in JcomboBox
| Thread Tools | Search this Thread |
911 addball addressbook android api append applet application array arrays automation binary bluetooth button character chat class classes client code component css csv database draw eclipse ee error event exception fractal game givemetehcodez graphics gui html ide image input integer j2me japplet java javaarraylist javaprojects jmf jni jpanel julia jvm key linked linux list loan loop map method methods mobile netbeans newbie objects oracle oriented output panel phone print printf problem program programming project projects recursion replaydirector reporting researchinmotion robot scanner screen se server service set size sms software sort sql string swing test threads time transfer tree ubuntu windows







