Java String concat() method


In this program, You will learn how to implement the String concat() method in java.


if (a.concat(b)) { 
    //statement
}

Example: How to implement the String concat() method in java.

import java.util.Scanner;

class Main {
    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        String a, b;

        System.out.print("Enter first string:");
        a = sc.nextLine();

        System.out.print("Enter second string:");
        b = sc.nextLine();

        a = a.concat(b);
        System.out.print("After concat :" + a);

    }
}

Output:

Enter first string:Xiith
Enter second string:.com
After concat :Xiith.com