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. Recover/retrieve deleted files

Hello,

Is there a Java or C API to retrieve deleted files on the phone? I
know that when we delete a file, only the TOC of the drive is
modified, not the drive's cluster.

Thanks.

-- 

2. GPS Road Network Developer

I know Waze exists already but in all honesty it's far from good,
often having roads that don't exist, not tracking very well, and
extremely difficult to edit roads that you've recorded afterwards.
What I am wondering is, how easy would it be to create an app that
follows me whenever I'm driving recording the road as I go, and
assuming I drive the same road again it refines the original road by
combining the gps tracks rather than creating a new one (as Waze seems
to like doing). This is something I would love to create but I don't
know if I have the technical know-how to do. Any help or suggestions
would be great!

Thanks, Ben

-- 

3. How to use "onTap" method to return to previous activity

4. Search function in Contact, Android 2.2

5. Issue during compilation of Android for beagle board

6. Porting/Development of Simtool kit on Android

7. Preferences, Data Files, and SQL DBs when an application updates from the market?