OneBite.Dev - Coding blog in a bite size

concatenate a string in java

Code snippet on how to concatenate a string in java

  String a = "Hello";
  String b = "World!";
  String c = a + " " + b;

The code above is an example of how to concatenate two strings in Java. Concatenation is the process of combining strings together. In this example, two strings called a and b are declared and assigned values. The third string c is then given a value that is the combination of strings a and b separated by a space. Therefore, string c will have the value “Hello World!” after the code executes. The plus sign (+) is used to combine the two strings together and the space gives the resulting string a space between the two words. This is a very simple example of string concatenation in Java, but it can become much more complex depending on the application.

java