Check out example codes for "java concatenate strings". It will help you in understanding the concepts better.

Code Example 1

String firstName = "BarackObama";
String lastName = " Care";
//First way
System.out.println(firstName + lastName);
//Second way
String name = firstName + lastName;
System.out.println(name);
//Third way
System.out.println("BarackObama" + " Care");

Code Example 2

public class Concat {
    String cat(String a, String b) {
        a += b;
        return a;
    }
}

Code Example 3

// CPP program to concatenate 
// two integers into one 
  
#include <iostream> 
#include <string> 
using namespace std; 
  
// Function to concatenate 
// two integers into one 
int concat(int a, int b) 
{ 
  
    // Convert both the integers to string 
    string s1 = to_string(a); 
    string s2 = to_string(b); 
  
    // Concatenate both strings 
    string s = s1 + s2; 
  
    // Convert the concatenated string 
    // to integer 
    int c = stoi(s); 
  
    // return the formed integer 
    return c; 
} 
  
int main() 
{ 
    int a = 23; 
    int b = 43; 
  
    cout << concat(a, b) << endl; 
  
    return 0; 
} 
  
// This code is contributed by Ayush Singla(@ayusin51)

Code Example 4

class Main
{
	public static void main(String args[])
    {
		String myString = "";
      	for (int i = 0; i < 3; i++)
        {
        	myString += "Hello There "; 
        }
      	System.out.println(myString); // Hello There Hello There Hello There 
    }
}

Learn ReactJs, React Native from akashmittal.com