← All resources

Write a program to demonstrate the joining of two strings using the concat() function

Description

This method appends one String to the end of another. The method returns a String with the value of the String passed into the method, appended to the end of the String, used to invoke this method.

Syntax

Here is the syntax of this method ?

public String concat(String s)

Parameters

Here is the detail of parameters ?

  • s is the String that is concatenated to the end of this String.

Return Value

  • This methods returns a string that represents the concatenation of this object’s characters followed by the string argument’s characters.

Example

import java.util.*;
public class Concatting
{
    public static void main()
    {
        Scanner sc = new Scanner(System.in);
        String s1, s2, s3;
        System.out.println("Enter first string:");
        s1 = sc.nextLine();
        System.out.println("Enter second string:");
        s2 = sc.nextLine();
        s3 = s1.concat(s2);
        System.out.println("Joined String: "+s3);
    }
}