Playing with String (An special class) class
- Example of creating String class instance
- Now check below declaration’s (Yes, both below are different)
String Concatenation: use numeric addition if two numbers are involved, use concatenation otherwise, and evaluate from left to right.
Immutable String: Once a String object is created, it is not allowed to change. It cannot be made larger or smaller, and you cannot change one of the characters inside it.
- immutable classes in Java are final, and subclasses can’t add mutable behavior
String Pool: Strings use a lot of memory. In some applications, they can use up 25–40 percent of the memory in the entire program. Java realizes that many strings repeat in the program and solves this issue by reusing common ones. The string pool, also known as the intern pool, is a location in the Java virtual machine (JVM) that collects all these strings.
- The string pool contains literal values that appear in your program.
- Now check below declaration’s (Yes, both below are different)
String methods:
Method Chaining:
|