Submit Your Email Now : To get latest programming tutorials directly in your inbox ! Hurry Up !!

Sunday, February 3, 2013

Write a program in Java to concatenate two Strings

What is String concatenation ?
String concatenation refers to the operation of  appending one String to the end of another String and form a single String using + operator.

Example :-
                   String s1,s2,s3;
                   s1="Alex ";
                   s2="is a superhero."
                   s3=s1+s2;
                   System.out.println(s3);
                   output: Alex is a superhero.
Also Read: String in Java Part-2 ( String Concatenation )

Objective Of The Program :
This program will display two Strings  as in Output -
1st String  : By concatenating two String objects
2nd String : By Concatenating Two Strings

Complete Program To Concatenate Strings In Java

//source code by CodingMagazine.blogspot.in
class concat{
 public static void main(String args[])
  {
   String s1,s2,s3;
   s1="Alex ";
   s2="is a super hero";
   //concatenation of string objects
   s3=s1+s2;
   System.out.println(s3);
   //concatenation of Strings
   System.out.println("Super Hero "+"Always Favorites");
  }
 }
 Output Should Be :
         Alex is a super hero
         Super Hero Always Favorites
         
Need Help ??
Run the above program and see the output. if you fails then please inform me by using below comment form.
waiting for your success story :)

SHARE THIS POST   

  • Facebook
  • Twitter
  • Myspace
  • Google Buzz
  • Reddit
  • Stumnleupon
  • Delicious
  • Digg
  • Technorati
If you enjoyed this post and wish to be informed whenever a new post is published, then make sure you Subscribe to our regular Email Updates!
Author: Sarada Prasad
Sarada Prasad is an IT professional working in a Multinational IT company. He loves to write on Programming, Social Media, Blogging and SEO. Read More →

0 comments: