Posts

Introduction to String Class in Java

Image
  What is  String  in Java? String is a sequence of characters. But in Java, String is an object that represents a sequence of characters. String class is in java.lang package . All string literals in Java programs, such as “hello”, are implemented as instances of String class. Strings are immutable; they are constant; their values cannot be changed after they are created. What are Literals? A Java literal is any value we specify as a constant in the code. It can be of any type — integer, float, double, long, String, char, or boolean. String Literal Any text between double quotes is a String literal. String literals can be on one line. If you want to have multi-line, you must use String concatenation (+) and new line character (\n). Below example shows single line String literal and multiline String literal. The output: Hierarchy of String class Java String class implements three interfaces. (Since the most super class is Object class String also extends Object class.) Ch...