32 lines
856 B
Plaintext
32 lines
856 B
Plaintext
module StringAppend {
|
|
void run() {
|
|
String start = "hello";
|
|
String finish = " world";
|
|
|
|
// approach #1: add strings together
|
|
String approach1 = start + finish;
|
|
|
|
// approach #2: StringBuffer
|
|
String approach2 = new StringBuffer()
|
|
.append(start)
|
|
.append(finish)
|
|
.toString();
|
|
|
|
// approach #3: string template
|
|
String approach3 = $"{start}{finish}";
|
|
|
|
@Inject Console console;
|
|
console.print($|
|
|
|Appending strings:
|
|
|
|
|
| {start=}
|
|
| {finish=}
|
|
|
|
|
| {approach1=}
|
|
| {approach2=}
|
|
| {approach3=}
|
|
|
|
|
);
|
|
}
|
|
}
|