Concatenate Java Strings Code Example


Example 1: String concatenation in java


// String concatenation in java using concat() method
public class StringConcatMethodDemo
{
public static void main(String[] args)
{
String str1 = "Flower ";
String str2 = "Brackets";
String str3 = str1.concat(str2);
System.out.println(str3);
}
}

Example 2: string concat in java


public class ConcatenationExample {
public static void main(String args[]) {
//One way of doing concatenation
String str1 = "Welcome";
str1 = str1.concat(" to ");
str1 = str1.concat(" String handling ");
System.out.println(str1);

//Other way of doing concatenation in one line
String str2 = "This";
str2 = str2.concat(" is").concat(" just a").concat(" String");
System.out.println(str2);
}
}

Comments

Popular posts from this blog

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android How Can I Convert A String To A Editable