There will be n number of objects because your result have n string.

I am not sure if you are referring to "cat_id" which is a compile time
constant and therefore will be interned and will not be created n times.
Regards,
Chandra


-----Original Message-----
From: A mailing list for discussion about Sun Microsystem's Java Servlet
API Technology. [mailto:[EMAIL PROTECTED]]On Behalf Of
Sushil Singh
Sent: Tuesday, June 12, 2001 7:23 PM
To: [EMAIL PROTECTED]
Subject: Basic Object Reference Question


Hi,

I am having a basic object reference question. Consider the following
code snippet:
      while (rootRs.next())
      {

categories.addElement(getCategory(rootRs.getString("cat_id")));
      }

Another code snippet:
     String catID = "";
      while (rootRs.next())
      {
           catID = rootRs.getString("cat_id");
           categories.addElement(getCategory(catID));
      }

Now my question is which one is better?  When we say

categories.addElement(getCategory(rootRs.getString("cat_id")));

then we are getting a reference to the resultset string object or its
new object. If its a new String object, then the while loop will be
creating n no of objects throughout the loop!!!

Awaiting your feedback.

Thanks. in advance.

Sushil

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to