String

  • String literal: A string Literal in Java is basically a sequence of characters from the source character set.
  • String in Java is an Immutable Class
  • String literals initialised are an object of this String class.

💡 While printing an object, Java compiler implicitly calls toString() method.

null vs empty String

String getSome;
String getMose = "";

Both of them are not the same. "" is a literal and has a reference pointing to it in the String constant pool, while getSome has no value/reference in it so its null → default value for String.


Children
  1. String Buffer
  2. String Builder
  3. String Comparison

Backlinks