Advertisement
public String concat(String st)
// Program to concatenate values in two String Objects.
class StringCon1
{
public static void main(String[] ar)
{
String str1 = new String("Hello");
String str2 = new String("World");
System.out.println("First String value : "+ str1);
System.out.println("Second String value : "+ str2);
System.out.println("Concatenated strings : "+ str1.concat(str2));
}
}
First String value : Hello
Second String value : World
Concatenated strings : HelloWorld
// Program to concatenate values in two String Objects.
class StringCon1
{
public static void main(String[] ar)
{
String str1 = new String("San");
String str2 = new String(" Franciso");
System.out.println("First String value : "+ str1);
System.out.println("Second String value : "+ str2);
System.out.println("Concatenated strings : "+ str1.concat(str2));
System.out.println("Value in the first String, post concat() : " + str1);
}
}
First String value : San
Second String value : Francisco
Concatenated String value : San Francisco
Value in the first String, post concat() : San
Advertisement
// Program to concatenate values in two String Objects.
class StringCon2
{
public static void main(String[] ar)
{
String str1 = new String("South");
String str2 = new String(" Africa");
System.out.println("First String value is: "+ str1);
System.out.println("Second String value is: "+ str2);
str1 = str1.concat(str2);
System.out.println("Value in the first String after concatenation with the second String : "+ str1);
}
}
First String value is: South
Second String value is: Africa
Value in the first String after concatenation with the second String : South Africa
Advertisement
Advertisement
Please check our latest addition
C#, PYTHON and DJANGO
Advertisement