Java String concat() method


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


if (a.concat(b)) { }


Example: How to implement String concat() method in Java

Run it Now
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("\nEnter Second String :");
        b = sc.nextLine();

        a = a.concat(b);
        System.out.print("\nAfter Concatination :" + a);

    }
}

Output:

Enter First String :Welcome
Enter Second String :John
After Concatination :WelcomeJohn