How to Concatenate Strings
The String class incorporates a function for connecting two strings:
mystring1.concat(mystring2);
This returns another string that is mystring1 with mystring2 added to it toward the end.
You can likewise utilize the concat() system with string literals, as in:
“My name is “.concat(“mary”);
Strings are all the more usually concatenated with the + administrator, as in:
“Hi,” + ” world” + “!”
which brings about:
“Hi, world!”
Sample Implementation:
public class MyString {
public static void main(string args[]) {
String mystr = “Sorry”;
System.out.println(“I ” + “am ” + mystr);
}
This would deliver the accompanying result:
I am Sorry
Do'stlaringiz bilan baham: |