• Post Reply Bookmark Topic Watch Topic
  • New Topic

Vector VS. Array, which has smaller size?  RSS feed

 
Ranch Hand
Posts: 222
  • Mark post as helpful
  • send pies
  • 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
  • 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 ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!