Java Strings are not constants - they are immutable. This means that once a
String object is created it cannot be changed. It also means that when you
pass a String as a argument to a method a new String is created that has the
same value but is nonetheless a different object. This works similiar to
pass-by-value for primitive types like int. On the other hand, the reference
that you hold to a String object can be reassigned to a new String object.
-----Original Message-----
From: abhishek shodhan [mailto:[EMAIL PROTECTED]]
Sent: Monday, July 31, 2000 11:08 PM
To: [EMAIL PROTECTED]
Subject: Re: [Re: Proprtionate String Padding]
Java Strings are not advisable as far as possible as each new String Object
will need to be Created in the Memory, and hence will slow down the
Application/Page. and considering that we are programming on the web, we
might
assume that we would get a lot of Hits on the JSP page. That will create
even
more Threads of Code, and hence even more String Objects.
String Buffers, on the other hand are easier to manage and Easier on the
Server.
Why do you need to Pad the String anyway? Just thinking... why not Trim it?
(String.trim())
Love Always,
Abhishek Shodhan.
B R Nair <[EMAIL PROTECTED]> wrote:
Thanks a lot Santosh, Naresh & Richard for your invaluble input.
"Strings are constant; their values cannot be changed after they are
created. String buffers support mutable strings." & "A string buffer is
like a String, but can be modified."
Whenever I read the above Java lanuage documentation, I am a lot more
confused.
If a string is constant, I should not be able to change its value after it's
created. But I can change the value of the string at my will (My experiments
show it *). Then, why we should we use StringBuffer instead of string when
both give the same result?
Thanks and regards
BRN.
*
public class Strpad
{
public static void main(String[] Arg)
{
String s = "String";
String a = s;
String b = "Buffer";
String m = "mutable";
String p = "padding -> ";
String c = s+ " " + p;
for (int i = 1;i<11;i++)
c = c + i;
System.out.println(c);
System.out.println();
StringBuffer sb = new StringBuffer(s+b+" "+p);
for(int i=1;i<11;i++)
sb.append(i);
String d = sb.toString();
System.out.println(d);
System.out.println();
a = a + " is (not) " + m + "?";
System.out.println(a);
}
}
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
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
____________________________________________________________________
Get free email and a permanent address at http://www.amexmail.com/?A=1
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
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".
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