Tell me more ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

What are the differences between these two data structures and where should you use each of them?

share|improve this question
did you tried to read java generics? – Zagorulkin Dmitry Jul 2 '12 at 10:15
1  
Think of vectors as resizable arrays. Vectors are dynamically-allocated. Vectors are represneted internally using arrays. See stackoverflow.com/questions/2871775/j2me-arrays-vs-vector – Emmad Kareem Jul 2 '12 at 10:29

closed as off topic by maple_shaft Jul 2 '12 at 11:36

Questions on Programmers Stack Exchange are expected to relate to software development within the scope defined in the FAQ. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about closed questions here.

2 Answers

up vote 3 down vote accepted

the primitive array (declared as Object[]) has a fixed size and isn't that usefull outside using APIs of libraries using them or a quick temporary

the Vector (declared as Vector<Object>) is a legacy class representing a variable size array and again not usefull outside the library APIs

what you should use is the ArrayList (declared as ArrayList<Object but you should use the List interface) this is also a variable size array and is a bit more efficient as it doesn't have needless thread safety overhead Vector has

share|improve this answer

just look at the docs, and don't use either btw, use something from the collections library

share|improve this answer
2  
-1 for "RTFM". Thanks, but don't really need that here. – DeadMG Jul 2 '12 at 10:43