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. How to force screen to switch between landscape/portrait

Is there a way to programmatically force the screen to change between landscape 
and portrait mode? I want to allow the user to choose a menu item to rotate the 
screen, instead of relying on pulling out the keyboard.

I am looking for something like Activity.changeScreenOrientation, but couldn't 
find such a thing in the API docs ...

Thanks


      

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

2. Capturing PCM/YUV samples,encoding, writing in a specific format

I have built PV core outside android. i would like to know how to make
the core accept data from the mic or camera-> encode it in a specific
format -> write in a specific file format.

What should I do to have a working graph like this ?
Source -> microphone
sink-> file writer (3gp)
interim-> amr codec
--~--~---------~--~----~------------~-------~--~----~

3. Problem with textalign

4. Questions in Calling Operation

5. why Android disable wlan interface when receive EVENT_SUPPLICANT_DISCONNECT

6. Distributing

7. how to see sms file.