Personally speaking i'd go in for the first approach because according to me
it would be more efficient if there are a lot of ResultSet Objects that
would have to be traversed in the while loop and i really don't find any use
of storing the String in a variable except for the fact that it makes your
code a little more cleaner and easier to follow.
Lastly, do remember that Strings are immutable objects in java.
Hope that helps :-).
Have a nice day.
With regards,
Sachin S. Khanna
http://www.emailanorder.com
----- Original Message -----
From: Sushil Singh <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, June 13, 2001 7:55 AM
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: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
> For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
DIGEST".
> Some relevant FAQs on JSP/Servlets can be found at:
>
> http://java.sun.com/products/jsp/faq.html
> http://www.esperanto.org.nz/jsp/jspfaq.html
> http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
> http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
>
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets