• 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

memory allocation for hashmap and arraylist

 
Greenhorn
Posts: 4
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I suppose hashmap is better in performance when compared to an arraylist. But can anyone let me know which occupies more memory - hashmap or an arraylist ?

Thanks,
Deep
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


I suppose hashmap is better in performance when compared to an arraylist.


What makes you suppose that? Performance doing what?
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The two are totally different. No comparison. Both give very fast lookup with their get() methods. But they are used for completely different tasks. It is rather like asking which is faster, a bicycle or a sailing boat. No comparison, unless you are used to cycling across the sea!
Don't know which uses more memory; I suspect a Map because it maintains two references for each Entry.
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ArrayList, vector and all map allocates a default initial memory of 10 objects.
In case of ArrayList, when a request of 11th object comes it increases to 1.5 times of present size ie 10 --> 15 --> 22...
In case of Vector, when a request of 11th object comes it increases to 3 times of present size ie 10 --> 20 --> 40...
In case of Map, when it is .75 (equal to load factor) full object comes it increases to 2.0 times of present size ie 10 --> 15 --> 22...


NOTE :- in case of Vector instead of incretement to double you can define increment size. then it will increase only that no of objects only not Double.

 
Campbell Ritchie
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why have you reopened such an old thread?

Maps usually have capacities which are exact powers of 2 (I think): default size = 16: when you pass the 75% load factor it enlarges to 32. That makes it easier to use the hashcode.
reply
    Bookmark Topic Watch Topic
  • New Topic