• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Map<Integer,Integer> or Map<String,String>

 
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Bartender
Posts: 4568
9
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Ranch Hand
Posts: 136
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic