Home » Java programs » Java String programs

Java program to concatenate two strings

In this java program, we are going to learn how to concatenate two strings? Here, we have two strings which will be entered through the user and we will concatenate them.
Submitted by IncludeHelp, on November 19, 2017


    String 1: "Include"
    String 2: "Help"

    Final string after concatenating: "IncludeHelp"

Program to concatenate two strings in java

import java.util.Scanner;

public class StringConcatenation 
	public static void main(String args[])
	{   // creating object of the string s1,s2.
		String s1,s2;
		Scanner sc=new Scanner(System.in);
		// enter both the string one by one.
		System.out.print("Enter First String : ");
		System.out.print("Enter Second String : ");
		// here we print the whole string after concatenation.
		System.out.println("String After Concatenation : " +s1.concat(s2));


First run:
Enter First String : Include
Enter Second String : Help
String After Concatenation :IncludeHelp

Second run:
Enter First String : Java
Enter Second String : Programming
String After Concatenation : JavaProgramming

Was this page helpful? YES NO

Are you a blogger? Join our Blogging forum.

Comments and Discussions

We are using Google to publish ads on our website; Google has its own privacy policies. They may save log, cookies on your system. Google may also collect information of your system like IP address, region, city, country. For more details please go through the Google’s privacy policy.