codescracker


java

Java Program to Concatenate String



« Previous Program Next Program »


Concatenate String

To concatenate or to append one string to another string in Java Programming, you have to ask to the user to enter the two string and start concatenating one string into the other using the concat() function.

Java Programming Code to Concatenate String

Following Java Program ask the user to enter the two string to concatenate it using the function concat(). Here string of str2 will be appended at the end of the string str1 :

/* Java Program Example - Concatenate String */
		
import java.util.Scanner;

public class JavaProgram
{
   public static void main(String args[])
   {
      String str1, str2;
      Scanner scan = new Scanner(System.in);
 
      System.out.print("Enter First String : ");
      str1 = scan.nextLine();
      System.out.print("Enter Second String : ");
      str2 = scan.nextLine();
      
      System.out.print("Concatenating String 2 into String 1...\n");
      str1 = str1.concat(str2);
	  
      System.out.print("String 1 after Concatenation is " +str1);
   }
}

When the above Java Program is compile and executed, it will produce the following result:

Java Program concatenate two strings

Same Program in Other Languages

You may also like to learn and practice the same program in other popular programming languages:


« Previous Program Next Program »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test