String->Integer Hashmap alternative

by al capwn » Fri, 10 Apr 2009 22:17:04 GMT


Sponsored Links
 Currently, I'm using a hashmap which maps strings to integers. I've read
that using a wrapper for a primitive type in a hashmap has extra cost and
was wandering if there is an alternative I could use.

I've seen sparsearrays in the sdk, but they map ints to objects but I need
the opposite. Is there an alternative to hashmap available for this or
should I write my own class to use an array of strings and a seperate array
of ints? If I do write my own class, is there a better implementation I
could do?

--~--~---------~--~----~------------~-------~--~----~



String->Integer Hashmap alternative

by Streets Of Boston » Fri, 10 Apr 2009 22:23:04 GMT


 If you mean you map 'String's to 'int's, then yes, you have some
overhead because of the autoboxing of Java, making 'int's into
'Integer's.

If your map's keys (in this case Strings) can be any possible String,
i would just use a Map<String, Integer>.

Depending on how you use this map, you should create a TreeMap or a
HashMap. TreeMap is more expensive in modifying itself, but fast in
reading. HashMap is more expensive in reading, but faster in modifying
itself.

I don't know what your requirements are, but, in general, i would not
advice you to write your own Map implementation.




--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Other Threads

1. rebuild and compile android

hi I'm new to android and Java so pls help me..
my queries:-

1. is it possible to download complete android source code, build and
compile it ???

2. is it possible to squeeze the code to my requirement and, then
again build and compile it ???

3. is it also possible to deploy this squeezed code to a android
compatible phone ???

-- 

2. programming event happening NOW

DELHI COLLEGE of ENGINEERING , online coding competition
Bytes-The Online Coding Competition will be on 19 Feb 2011.
TIME : 9:00 p.m.
https://www.spoj.pl/BYTES11B/
Every participant should have an id at www.spoj.pl

-- 

3. Android 2.3 Vs 3.0

4. play video from input stream

5. How to change display name for aggregated contact programatically?

6. Sony - Theme 2.1 - android:paddingLeft on RadioButton

7. Android mic control via API