Share on Google+Share on Google+

Combine String example

In this section, you will learn how to combine or merge two strings in java.

Combine String example


In this section, you will learn how to combine or merge two strings in java. The java.lang package provides the method that helps you to combine two strings and making  into single string. The following program is used for concatenating two string through using the concat() method that concatenates the specified string to the end of string and finally, you will get the combined string. 

Description of code:

concat(String str):
This is the method that concatenates the two specified strings.

Here is the code of program:


public class CombinString{
  public static void main(String[] argsthrows IOException{
  BufferedReader bf = 
BufferedReader(new InputStreamReader(;
  System.out.println("Enter First String:");
  String str1 = bf.readLine();
  System.out.println("Enter Second String:");
  String str2 = bf.readLine();
  System.out.println("Combin string example!");
  String com = str1.concat(str2);
  System.out.println("Combined string: " + com);

Download this example.

Output of program:


C:\vinod\Math_package>java CombinString
Enter First String:
Enter Second String:
Combin string example!
Combined string: RoseIndiaNewstrackIndia



Posted on: June 8, 2007 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Discuss: Combine String example   View All Comments

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
February 16, 2012
C prog communicates with my sql db

Write a c prog to retrive time zone from my sql db