Search Java Programs

Wednesday, January 20, 2010

Java String concat Example

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

No comments:

Post a Comment

Website Design by Mayuri Multimedia