Learnerslesson
   JAVA   
  SPRING  
  SPRINGBOOT  
 HIBERNATE 
  HADOOP  
   HIVE   
   ALGORITHMS   
   PYTHON   
   GO   
   KOTLIN   
   C#   
   RUBY   
   C++   




Java - String Concatenation


In the earlier examples, we have seen the + sign. And as we know, + is used for addition of two numbers.


Well! In Java, + can be used to join two Strings as well.


Concatenation of Strings


Say, we have two Strings, Hello and World. And we want to join/concatenate them into one String, HelloWorld.


Let us solve it with the below example.


Example :



public class MyApplication
{
    public static void main(String[] args)
    {
        String x = "Hello";
       	String y = "World";
       	String z = x + y;
       	System.out.println(z);
    }
}


Output :



  HelloWorld

So, we have stored the String Hello in x.


String x = "Hello";

And, stored the String World in y.


String y = "World";

And used the + operator to join/concatenate Hello and World.


String z = x + y;

And store the concatenated value in z.

Spring_Boot

So, + is not just used to add two numbers but + is also used to join/concatenate two Strings.


Next, let us see, how can we iterate the elements of a String.