if we have to implementations of string split for j2me, one returns vector and the other returns array , in terms of performance on hand held devices which one is the best choice ?
+1
A:
Arrays would always perform better than Vector
, although the difference should not be too significant. The real question is whether this performance is worth the sacrifice of not having the rich functionalities provided by Vector
, e.g. being dynamically growable, etc.
Generally speaking you should always prefer List
to arrays (see Effective Java 2nd Edition, Item 25, Prefer lists to arrays), but J2ME development may not give you the luxury.
polygenelubricants
2010-05-20 07:35:31
Can you elaborate on the reason here? I don't have access to the book.For me, using Array will be preferred because via List, it will be a virtual call and hence slower.
MasterGaurav
2010-05-20 07:46:09
@MasterGaurav: performance was not even discussed in the chapter; the main issues are type-safety (`List` is invariant, arrays are covariant), richer functionality, interoperability with the rest of the Collections Framework, etc. Again, this item may or may not be applicable to J2ME development. It should be said that good design is usually more important than performance, and that you should not prematurely optimize.
polygenelubricants
2010-05-20 07:52:30
+1
A:
Vector
is deprecated.
If you don't need to alter the results, use array - it will have less overhead as well as less flexibility.
MasterGaurav
2010-05-20 07:36:18
Have a look at for instance http://java.sun.com/javame/reference/apis/jsr118/ You won't even find ArrayList, and Vector is definately not marked as deprecated.
aioobe
2010-05-20 07:39:14