Macey  Legros

Macey Legros


Java String Class Example | String Class in Java Tutorial

Java String is an inbuilt class that deals with all that is written in double quotation marks, or other words string is a collection of characters. For example – “Java” is a String of length 4.  Every string is an instance of this class. They are immutable, and so once written, and their value cannot be changed.

See the following figure.

Java String Class Example

The string is a sequence of characters. In Java, objects of String are immutable, which means a constant and cannot be changed once created. The java.lang.String class provides a lot of functions to work on the string. With the help of these functions, we can perform the operations on string such as trimming, concatenating, converting, comparing, replacing strings, etc.

#Why Strings are immutable or final in Java

Strings are used as parameters for many Java classes e.g.

  1. For opening a network connection.
  2. For opening a database connection.
  3. For File handling.

In case if strings were not immutable, this would have jeopardized the security.

#java #java string class #java.lang.string

Java String Class Example | String Class in Java Tutorial