This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring in Action (5th edition) and have Craig Walls on-line!
See this thread for details.
Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Array vs Vector  RSS feed

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,
What's the difference between array and vector?
What's the advantage and disadvantage of them?
thanks
Larry
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!