Java StringBuilder to concatenate strings - Sample Code
Please find the usage below
System.out.println("request params :"
+ " contextPath=" + pRequest.getContextPath()
+ ", " + PATH_Info + "=" + pathInfo
+ ", " + BASIC_AUTH + "=" + basicAuth
+ ", " + FORM_AUTH + "=" + formAuth
+ ", " + FORCE_LOCALE_PARAM + "=" + forceLocale
);
The above concatenation can be achieved as given below,
String [] stringConcatArray = {"request params :"," contextPath=",pRequest.getContextPath),PATH_Info,"=",pathInfo,BASIC_AUTH,"=",basicAuth,FORM_AUTH,"=",formAuth,
FORCE_LOCALE_PARAM,"=",forceLocale};
System.out.println(stringConcat(stringConcatArray));
Add below method in your StringUtil Class.Any number of string arguments can be passed to this method to get it concatenated to one string.
public static String stringConcat(String args[]) {
StringBuilder builder = new StringBuilder();
for (String strVal : args)
builder.append(strVal);
return builder.toString();
}
Comments
Post a Comment