• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Vector VS. Array, which has smaller size?

 
Ranch Hand
Posts: 222
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm writing a map editor for a game, the structure is like this:
data[L][X][Y]
L: level index
X: x position
Y: y position
assume L, X, Y are constants, if i write it in this way:
Vector LData;
Vector XData = LData.get(Xindex)
Vector YData = XData.get(Yindex)
so everything in array data is included in a vector LData, but i wonder:
1. which way is faster?
2. which way uses less memory?
2. which way do you prefer?
thank you.
 
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since jdk 1.2 Vector has been retrofitted to implement the List interface and therefore become a member of the Collections framework. This has led to the practice of defining your collections by their Interface. For example
However if your collection doesn't need synchronization you could always change the above code to:
without your program being impacted too much.

Read The Collection Trail by Joshua Bloch

Originally by Joshua Bloch:

If you need synchronization, a Vector will be slightly faster than an ArrayList synchronized with Collections.synchronizedList, but Vector has loads of legacy operations, so be extra careful to always manipulate the Vector with the List interface, or you'll be stuck with it for life.



and remember that the Collection framework allows for custom implementations with the aid of the abstract implementations already provided by the Java platform.
[ November 08, 2004: Message edited by: Nigel Browne ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic