[Logo]
Forums Register Login
Array vs Vector
Hi everyone,
What's the difference between array and vector?
What's the advantage and disadvantage of them?
thanks
Larry
look at the api's '
array cannot get larger vectors can
vector contains objects not primitives..
if you want to store primitives you should use a wrapper etc....
but then again look at the
Api
[ May 21, 2002: Message edited by: Robert Ziel ]
Vectors can only store objects so you always need to cast when you take the object out of the vector. Arrays can be created to hold a specific type of object (Button[] b = new Button[10] . Arrays are almost always faster than vectors. Vectors are synchronized.
"Behind every Vector is a good array"
In real life a Vector is a lot of bells and whistles and functionality around an array.
If you want the functionality provided for you - use Vector and accept the overhead.
If you uses are simple or you want to use primitives without putting them in wrappers - use arrays.
From the source code for Vector:
look! it's a bird! it's a plane! It's .... a teeny tiny ad
The WEB SERVICES and JAX-RS Course
https://coderanch.com/t/690789/WEB-SERVICES-JAX-RS


This thread has been viewed 536 times.

All times above are in ranch (not your local) time.
The current ranch time is
Feb 25, 2018 16:16:48.