Home » Java programs » Java String programs

Java program to concatenate two strings without using library function



In this java program, we are going to learn how to concatenate two strings without using library function?
Submitted by Preeti Jain, on March 13, 2018

First way is to write a program with the help of library function (concat) in java, read here: Java program to concatenate two strings

Second way is to write a program without the help of library function means we can make a program manually or our programming logic there is no need to use any readymade function.

Program to concatenate two strings without using library function in java

import java.util.Scanner;

class ConcatenateString{
	public static void main(String[] args){
		/* create Scanner class object */
		Scanner sc = new Scanner(System.in);
		
		/* Display message for user to take first 
		string input from keyboard */
		System.out.println("Enter First String :");
		String firstStr = sc.next();
		
		/* Display message for user to take first 
		string input from keyboard */
		System.out.println("Enter Second String :");
		String secondStr = sc.next();
		
		/* Display message for displaying result */
		System.out.println("Result after concatenation:");
		
		/* '+' operator concatenate string */
		System.out.println(firstStr+ " " + secondStr);
	}
}

Output

D:\Java Articles>java ConcatenateString
Enter First String :
preeti
Enter Second String :
jain
Result after concatenation:
preeti jain





Was this page helpful? YES NO

Are you a blogger? Join our Blogging forum.



Comments and Discussions





© https://www.includehelp.com (2015-2018), Some rights reserved.




close Like other websites, this site uses cookies to deliver relevant ads based on your interest, by using our website, you acknowledge that you have read our privacy policy.