• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Default Object and String sizes?

 
Roger Graff
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does anyone know what the default Object and String sizes are?
How about HashMap and ArrayList?
Thanks!
Graff
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • 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
  • 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();
 
Snigdha Solanki
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • 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
  • 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!
 
Michael Matola
whippersnapper
Ranch Hand
Posts: 1821
4
  • Mark post as helpful
  • send pies
  • 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 ]
 
Anthony Villanueva
Ranch Hand
Posts: 1055
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Follow this thread.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic