I've heard that the compiler will internally create a StringBuffer for you.
However, it may vary from compiler to compiler and thus the second method
may be preferred. One additional optimization is to specify the initial
size of the StringBuffer. That way, you can save on the StringBuffer having
to resize itself.
-Richard
At 01:45 PM 8/31/2005, you wrote:
>Hi,
>I have a question in string concatenation.
>
>I have the below code.
>
>StringBuffer a = new StringBuffer();
>a.append("Name=" + userVo.getName());
>a.append("Id = " + userVo.getId());
>a.append("Sno="+userVo.getSno());
>a.append("Sno1="+userVo.getSno1());
>
>Instead of using + to append strings, if I concatenate strings as below,
>will it be faster than the above one?
>Is not for the below , only few strings get used.So, is the below one
>better than the above?
>
>StringBuffer a = new StringBuffer();
>a.append("Name=").append(userVo.getName()));
>a.append("Id = ").append(userVo.getId()));
>a.append("Sno=").append(userVo.getSno()));
>a.append("Sno1=").append(userVo.getSno1()));
>
>
>Thanks in advance.
>
>===========================================================================
>To unsubscribe, send email to listserv@(protected)
>of the message "signoff J2EE-INTEREST". For general help, send email to
>listserv@(protected)".
===========================================================================
To unsubscribe, send email to listserv@(protected)
of the message "signoff J2EE-INTEREST". For general help, send email to
listserv@(protected)".