• 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

Default Object and String sizes?

 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does anyone know what the default Object and String sizes are?
How about HashMap and ArrayList?
Thanks!
Graff
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What do you mean b default sizes? The size of an object or string depends on what the object is or what is in the string.
HashMap and ArrayList??? I you trying to find the differences or whic one will be appropriate for you to use.
Any good textbook, will have some information on these.
 
Roger Graff
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've thumbd through Eckel's book and Mugal's book and cannot find the answer that I'm looking for.
I am referring to the size of:
new Object();
new String("");
new HashMap();
new ArrayList();
 
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Size of new String("");
new HashMap();
new ArrayList();
will be 0.
 
Roger Graff
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Snigdha Solanki:
Size of new String("");
new HashMap();
new ArrayList();
will be 0.


I don't want to know how many characters/Objects/key-value pairs are in these. I want to know how much memory is allocated to each of these objects.
Thanks for responding anyway!
 
whippersnapper
Posts: 1843
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Roger, I don't think there's any way of directly knowing the "size" of an object in Java. (Someone please correct me if I'm wrong.)
If you are comparing objects you can use the == operator (identity) or equals method (equality, however defined for the given object), depending on what you're after.
If you need to know what the class of a given object is, you can use the instanceof operator (or in some cases you may want to use the class's Class object).
[ June 26, 2002: Message edited by: Michael Matola ]
 
Ranch Hand
Posts: 1055
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Follow this thread.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic