GeeCON Prague 2014*
The moose likes Java in General and the fly likes Default Object and String sizes? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "Default Object and String sizes?" Watch "Default Object and String sizes?" New topic
Author

Default Object and String sizes?

Roger Graff
Ranch Hand

Joined: May 29, 2001
Posts: 112
Does anyone know what the default Object and String sizes are?
How about HashMap and ArrayList?
Thanks!
Graff
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
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.


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Roger Graff
Ranch Hand

Joined: May 29, 2001
Posts: 112
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

Joined: Sep 07, 2000
Posts: 128
Size of new String("");
new HashMap();
new ArrayList();
will be 0.


Snigdha<br />Sun Certified Programmer for the Java™ 2 Platform
Roger Graff
Ranch Hand

Joined: May 29, 2001
Posts: 112
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

Joined: Mar 25, 2001
Posts: 1747
    
    2
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

Joined: Mar 22, 2002
Posts: 1055
Follow this thread.
 
GeeCON Prague 2014
 
subject: Default Object and String sizes?