File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Vector VS. Array, which has smaller size? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Vector VS. Array, which has smaller size?" Watch "Vector VS. Array, which has smaller size?" New topic
Author

Vector VS. Array, which has smaller size?

HaoZhe Xu
Ranch Hand

Joined: Nov 03, 2003
Posts: 222
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.


[url]Olnex.net[/url]
[SCJP 1.2, SCJD, SCWCD]
Nigel Browne
Ranch Hand

Joined: May 15, 2001
Posts: 673
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 ]
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Vector VS. Array, which has smaller size?
 
Similar Threads
Neef Help with Printing
Converting a two dimensional int array into a byte array
Array VS. Vector, which is better?
how to compare the values in arrays
Need help on animation using GUI Builder.