- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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);
- Related Articles
- Smart concatenation of strings in JavaScript
- Concatenation of strings in Lua programming
- Concatenation of two strings in PHP\n
- Concatenation of two strings in PHP program
- String Concatenation in Java
- Check if concatenation of two strings is balanced or not in Python
- Addition and Concatenation in Java
- C++ program to get length of strings, perform concatenation and swap characters
- Return a string which is the concatenation of the strings in the sequence in Numpy
- Java program for String Concatenation.
- Comparing Strings and Portions of Strings in Java
- Java String Concatenation with Other Data Types.
- String Concatenation by + (string concatenation) operator.
- Concatenation of tables in Lua programming
- Join Strings in Java

Advertisements