diff options
author | Nguyễn Gia Phong <vn.mcsinyx@gmail.com> | 2019-12-15 10:34:58 +0700 |
---|---|---|
committer | Nguyễn Gia Phong <vn.mcsinyx@gmail.com> | 2019-12-15 15:00:00 +0700 |
commit | 67393f42f41ab92219deb549f711121c4dab845b (patch) | |
tree | ebd0eb6c8a3d3bd69937312179aeaf273ea29c80 /usth/ICT2.2/labwork/1/string-concat.md | |
parent | b38d9929f7a015b56b847fde7e83f814f354497e (diff) | |
download | cp-67393f42f41ab92219deb549f711121c4dab845b.tar.gz |
[usth/ICT2.2] Object Oriented Programming
Diffstat (limited to 'usth/ICT2.2/labwork/1/string-concat.md')
-rw-r--r-- | usth/ICT2.2/labwork/1/string-concat.md | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/usth/ICT2.2/labwork/1/string-concat.md b/usth/ICT2.2/labwork/1/string-concat.md new file mode 100644 index 0000000..624383f --- /dev/null +++ b/usth/ICT2.2/labwork/1/string-concat.md @@ -0,0 +1,15 @@ +# String Concatenation + +To quote the [official Java documentation](https://docs.oracle.com/javase/8/docs/api/java/lang/String.html): + +> The Java language provides special support for the string concatenation +> operator (`+`), and for conversion of other objects to strings. [...] +> String conversions are implemented through the method `toString`, defined +> by Object and inherited by all classes in Java. + +Thus the numbers (e.g. 2, 2 + 3 = 5) are converted to their strings +representations ("2", "5") and concatenated to the string. Since `+` is +operated from left to right, + + 2 + 3 + "bc" = 5 + "bc" = "5" + "bc" = "5bc" + "bc" + 2 + 3 = "bc" + "2" + 3 = "bc2" + 3 = "bc2" + "3" = "bc23" |