- 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
String Concatenation in Java
You can concatenate two strings in Java either by using the concat() method or by using the ‘+’ , the “concatenation” operator.
The concat() method
The concat() method appends one String to the end of another. This method returns a String with the value of the String passed into the method, appended to the end of the String, used to invoke this method.
Example
public class ConncatSample { public static void main(String []args) { String s1 = "Hello"; String s2 = "world"; String res = s1.concat(s2); System.out.print("Concatenation result:: "); System.out.println(res); } }
Output
Concatenation result:: Helloworld
The ‘+’ operator
Just like the concat method the ‘+’ operator also performs the concatenation operation on the given operators.
Example
public class ConncatSample { public static void main(String []args) { String s1 = "Hello"; String s2 = "world"; String res = s1+s2; System.out.print("Concatenation result:: "); System.out.println(res); } }
Output
Concatenation result:: Helloworld
- Related Articles
- Java program for String Concatenation.
- String Concatenation by + (string concatenation) operator.
- Java String Concatenation with Other Data Types.
- Avoid Unexpected string concatenation in JavaScript?
- Concatenation of Strings in Java
- Addition and Concatenation in Java
- String Concatenation by concat() method.
- Why should you be careful about String concatenation (+) operator in loops using Java?
- Concatenation of two String Tuples in Python
- Python – Incremental Slice concatenation in String list
- C/C++ Macro for string concatenation
- How to perform string aggregation/concatenation in Oracle?
- Return element-wise string multiple concatenation in Numpy
- Golang Program to demonstrate the string concatenation
- Return element-wise string concatenation for two arrays of string in Numpy

Advertisements