Simple example to use string in different ways.
Syntax :
string1.concat(string2)
Example :
- public class StringConcatDemo {
- public static void main(String args[]) {
- String s = "Strings are immutable";
- s = s.concat(" all the time");
- System.out.println(s);
- }
- }
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