Following example shows String concatenation in Java using + operator and StringBuffer.append() method.
Sample Program
01.
package
com.javatutorialcorner.javastring;
02.
03.
public
class
StringConcatenation {
04.
05.
public
static
void
main(String[] args) {
06.
String plusOperator =
"Java tutorials corner "
07.
+
" contains tutorials for Java programers day to day needs tutorials"
08.
+
" like Java, Spring, Hibernate, String, JSON, Jackson, GSON,"
09.
+
" XML parsing, Web Service, SOAP Web Service, RESTful Web Service"
;
10.
11.
System.out.println(
"plusOperator : "
+ plusOperator);
12.
13.
StringBuffer stringBuffer =
new
StringBuffer();
14.
stringBuffer.append(
"Java tutorials corner "
);
15.
stringBuffer
16.
.append(
" contains tutorials for Java programers day to day needs tutorials"
);
17.
stringBuffer
18.
.append(
" like Java, Spring, Hibernate, String, JSON, Jackson, GSON,"
);
19.
stringBuffer
20.
.append(
" XML parsing, Web Service, SOAP Web Service, RESTful Web Service"
);
21.
22.
System.out.println(
"stringBuffer : "
+ stringBuffer);
23.
24.
}
25.
26.
}
Result
The above code will produce the following output.
plusOperator : Java tutorials corner contains tutorials for Java programers day to day needs tutorials like Java, Spring, Hibernate, String, JSON, Jackson, GSON, XML parsing, Web Service, SOAP Web Service, RESTful Web Service
stringBuffer : Java tutorials corner contains tutorials for Java programers day to day needs tutorials like Java, Spring, Hibernate, String, JSON, Jackson, GSON, XML parsing, Web Service, SOAP Web Service, RESTful Web Service
0 comments:
Post a Comment