Java String concat Example
String class Concat method example
String class Concat method example:- This example demonstrates the working of concat() method. This method just copies and adds up the data in to
the specified String in parentheses to String with which using dot the method is called.
Syntax:-concat(String str)
Here is the code:-
/**
* @(#) ConcatString.java
* ConcatString class demonstrates the working of concate() method of String class of lang package
* @version 14-May-2008
* @author Rose India Team
*/
public class ConcatString {
public static void main(String args[]) {
// concat() method is called 'add to' method as this method adds
// String,s
// value inside parentheses to the String left side of the assignment
// operater(=)
String str = "Combination of Astrology, Astronomy and Technology", str1 = "He ram ", str2 = " can lead to the invention of computers that can tell the incidents that will happen latter in time", heram = "", prabhu = "";
heram = str1.concat(str);
prabhu = heram.concat(str2);
System.out.println(prabhu);
System.out.println();
System.out.println("It can also b done in this way as:- '''System.out.println(str1 + srt + str2 );''' and result will be same below ");
System.out.println(str1 + str + str2);
System.out.println();
}
} |
Output of the program:-
He ram Combination of Astrology, Astronomy and Technology can lead to the invention of computers that can tell the incidents that will happen latter in time
It can also b done in this way as:- '''System.out.println(str1 + srt + str2 );''' and result will be same below
He ram Combination of Astrology, Astronomy and Technology can lead to the invention of computers that can tell the incidents that will happen latter in time
|
|