Java: Interesting and Cool Tricks

Leo N
Geek Culture
Published in
7 min readJun 30, 2021

--

👉 1 >> Java String

concat() Vs the + Operator for Concatenation

intern()

As you can see, both str1 and str2 have the same content, but they are not equal initially.

We then use the intern() method so that str1 and str2 use the same memory pool. After we use intern(), str1 and str2 are equal.

👉2 >> Comment

In Java, there are two types of comments:

  • Single-line comment: A single-line comment starts and ends in the same line. To write a single-line comment, we can use the // symbol. For example:
  • Multi-line comment: When we want to write comments in multiple lines, we can use the multi-line comment. To write multi-line comments, we can use the /*….*/…

--

--

Leo N
Geek Culture

🎓 “A person who never made a mistake never tried anything new.” — Albert Einstein