Here is the Program for
concatenation
of two String
Explanation of Program
In this example we have taken a String variable 'msg' in which we've assigned the value "My name is" after assigning the value we have concatenated with other String ' Sam' using + Operator.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | public class Ruler { public static void main(String[] args) { String msg = "My Name is" ; String msg = msg + " Sam" ; System.out.println(msg); } } /************************* * OUTPUT of Program * * My Name is Sam ************************/ |
Explanation of Program
In this example we have taken a String variable 'msg' in which we've assigned the value "My name is" after assigning the value we have concatenated with other String ' Sam' using + Operator.