Skip to main content

HOW TO CONCATENATE (join) TWO STRINGS

Simple example to use string in different ways.

Syntax :

string1.concat(string2)

Example :

  1. public class StringConcatDemo {
  2. public static void main(String args[]) {
  3.    String s = "Strings are immutable";
  4.    s = s.concat(" all the time");
  5.    System.out.println(s);
  6.    }
  7. }

Description :

Step 1:Starting of class
Step 2:Start of main function.
Step 3:Define a string "s"
Step 4:Concatenating data of string 's' with new data "all the time".
Step 5:Display content of variable "s" to console.

Output:

Strings are immutable all the time