Home Java Beginners Combine String example



Combine String example
Posted on: June 8, 2007 at 12:00 AM
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:

import java.io.*;

public class CombinString{
  public static void main(String[] argsthrows IOException{
  BufferedReader bf = 
new 
BufferedReader(new InputStreamReader(System.in));
  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>javac CombinString.java

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

Related Tags for Combine String example:
javacstringcomidestringshelpmethodsedgetviusingintidpackageifforiecombinefinalprogramconcatenatenattoramfinallysinglecilanbieildesusepeinconcatmntpstrcajpackesspecthroughendallagemehrintoproackcatbinsspatpackishallfollowandstrwingvatwssriringthavstatihatfinprndonombomogrolo


More Tutorials from this section

Ask Questions?    Discuss: Combine String example   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.