Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Concatenation of Strings in Java
You can finish your task by combining/ concatenating your two stings using concat() method or + operator.
Example
import java.util.Scanner;
public class ConncatSample {
public static void main(String []args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter your first name");
String firstName = sc.nextLine();
System.out.println("Enter your last name");
String lastName = sc.nextLine();
String completeName = firstName+lastName;
System.out.print("Hi your complete name is :: ");
System.out.println(completeName);
}
}
Output
Enter your first name KrishnaKasyap Enter your last name Bhagavatula
Hi your complete name is − KrishnaKasyapBhagavatula
You can also use the concat() method like −
String completeName = firstName.concat(lastName);
Advertisements