JAVA program to concatenate two strings without using string method concat()

JAVA program to concatenate two strings without using string method concat()

This JAVA program is to concatenate two strings without using string method concat().

For example str1=’code’ and str2=’dost’ then on concatenation the string would be ‘codedost’.

Logic

In java it is quite easy to concatenate two strings. We use ‘+’ operator in java for concatenation of two strings

Program

import java.util.*;

class stringConcat
{
	public static void main(String args[])
	{
		String str1,str2;
		Scanner sc = new Scanner(System.in);
		System.out.println("Enter the 1st string");
	 	str1=sc.nextLine();
		System.out.println("Enter the 2nd string");
	 	str2=sc.nextLine();
  		System.out.println("Concatenated String is ");
  		System.out.println(str1+str2);
	}
}

Output

Share Me!