Java Program to Concatenate two strings without using string functions


For eg.
Input: 1st String - Hello World
2nd String - Welcome to Java
Output: Hello World Welcome to Java

Concatenate two strings without using string functions using Java

Program 1:

import java.util.*; class StringConcat{ public static void main(String[] args){ int length1,length2; String word1,word2; char[] cword1,cword2,finalword; Scanner sc=new Scanner(; word1=sc.nextLine(); word2=sc.nextLine(); cword1=word1.toCharArray(); cword2=word2.toCharArray(); length1=word1.length(); length2=word2.length(); finalword=new char[length1+length2]; for(int k=0;k<length1;k++){ finalword[k]=cword1[k]; } for(int i=0,k=length1;k<(length1+length2);k++,i++){ finalword[k]=cword2[i]; } for(char word:finalword) System.out.print(word); } }

Program 2:

class ConcatenateString { public static void main(String args[]) { String string1,string2; Scanner sc = new Scanner(; System.out.println("Enter the 1st string"); string1=sc.nextLine(); System.out.println("Enter the 2nd string"); string2=sc.nextLine(); System.out.println("Concatenated String is "); System.out.println(string1+string2); } }
                  Liked Article? Please Buy me a Coffee 😭

Want to Clear Java Interview? Read Java Interview Notes prepared by Us

Are You Good enough in Java?

Learn Python in a Week and Master It


Need Programming Help??

Below Offers ends in

Quiz For You:

Search Tags

    Concatenate 2 strings without using java function

    Join 2 strings algorithm without java inbuilt method