views:

137

answers:

3

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
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
@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
+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
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
Ah! I mixed up with Java SE (J2SE) ;)
MasterGaurav
A: 

according to sun j2me performance tuning described in link text

"Arrays are usually faster and leaner than collection classes" , so its clear that using arrays will be much better than any collection object

Galaxy