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

Reply via email to