by BehindJava

WAP to Concatenate a given string to the end of another string in Java

Home » interview » WAP to Concatenate a given string to the end of another string in Java

In this tutorial we are going to learn how to write a program to Concatenate a given string to the end of another string in Java with both predefined input and custom user input.

class Main {

public static void main(String[] args){

String a ="Java tutorials and";
String b =" Springboot Framework";

System.out.println(a.concat(b));
}
}

Output:

Java tutorials and Springboot Framework

User input:

import java.util.Scanner;
public class Main {

public static void main(String[] args) {

java.util.Scanner input = new Scanner(System.in);

System.out.println("Please enter your first name: ");
String str1 = input.nextLine();
System.out.println("Please enter your surname: ");
String str2 = input.nextLine();

String str3 = str1.concat(str2);

System.out.println(str3);
}
}