• Post Reply Bookmark Topic Watch Topic
  • New Topic

Map<Integer,Integer> or Map<String,String>  RSS feed

 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have to store String values in a HashMap. The key and values will be only numerals in String representation. If I change them to Integer and use Map<Integer,Integer> instead of Map<String,String>, will it increase the performance a bit?
 
Matthew Brown
Bartender
Posts: 4568
9
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wouldn't expect it to make any significant difference. If they will always be integers though - and especially if they're going to be used as numbers at a later point - I'd probably convert them just to better represent what the data is. (It also means you'll catch errors - where the string isn't a number - earlier).
 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They wont be used as numbers. They will be just used to find a parent child mapping. I will resign with using String then.
Thanks Matthew!
 
Gaurav Raje
Ranch Hand
Posts: 136
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Personally i feel it would increase performance (a little)
Strings have an overhead of using the string pool. So when you create a key, a lot ot stuff happens.
Integers on the other hand are easier to create and destroy. Furthermore, Strings are backed by an array of characters. So a key like
11221 will be 10 byte while the same as an int would be 4 byte.

Again I might be wrong
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!