by Sai gowtham

How to concatenate strings in Java

To concatenate strings we need to use plus + operator in Java.

In this below example, we are concatenating two strings by using + operator.

String first = "Code";
String last  =  "examples";

String combine = first + last;

System.out.println(combine);

Output:

Codeexamples

Using concat() method

Similarly, you can also use the concat() method to concatenate one string with another string.

String name = "Code";

System.out.println(name.concat("Java"));

Output:

Codejava

Top Udemy Courses

JavaScript - The Complete Guide 2020 (Beginner + Advanced)
JavaScript - The Complete Guide 2020 (Beginner + Advanced)
45,614 students enrolled
52 hours of video content
View Course
React - The Complete Guide (incl Hooks, React Router, Redux)
React - The Complete Guide (incl Hooks, React Router, Redux)
284,472 students enrolled
40 hours of video content
View Course
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
130,921 students enrolled
48.5 hours of video content
View Course