Sunday 13, Apr 2025
We are moved to new domain
Click -> www.ehowtonow.com
Friday, 8 May 2015

String Concatenation in Java

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

Shop and help us

Flipkart Offer Snapdeal offer Amazon.in offer Amazon.com offer

Related Posts:

  • How to search a word inside StringFollowing program shows how to search the word inside a string using indexOf(String str) available in Java. The indexOf(String str)  method returns the position of word with in the string if found, otherwise it returns –… Read More
  • How to make collection read-only Following example shows how to make collection read-only using Collections.unmodifiableSet(collection) method in Java. <String> List<String> java.util.Collections.unmodifiableList(List<? extends String> li… Read More
  • How to search file from directory using Java String[] java.io.File.list(FilenameFilter filter) Returns an array of strings naming the files and directories in the directory denoted by this abstract pathname that satisfy the specified filter. The behavior of this metho… Read More
  • How to retrieve all the files from Directory using Java File.listFiles() File[] java.io.File.listFiles() Returns an array of abstract pathnames denoting the files in the directory denoted by this abstract pathname. If this abstract pathname does not denote a directory, then this method returns n… Read More
  • How to Create Directory using Java File.mkdirs boolean java.io.File.mkdirs() Creates the directory named by this abstract pathname, including any necessary but nonexistent parent directories. Note that if this operation fails it may have succeeded in creating some of th… Read More
  • Blogger Comments
  • Facebook Comments
  • Disqus Comments

0 comments:

Post a Comment

Item Reviewed: String Concatenation in Java Rating: 5 Reviewed By: eHowToNow