next up previous
Next: Example: initials of a Up: Unit 02 Previous: Example: program on strings

Example: string concatenation

Construction of the string "xxxyyyzzz", using variables and assignments:

String x = "xxx", y = "yyy", z = "zzz";
String temp = x.concat(y);
String result = temp.concat(z);
System.out.println(result);

We use one variable for each object and for each intermediate result.


next up previous
Next: Example: initials of a Up: Unit 02 Previous: Example: program on strings