All strings are objects belonging to the class String. As such, every string has certain behaviors that are defined by the methods in the class String.

The method length

The method length provides the number of characters that are in a string, including any spaces. For example, the statements in the following program display 21:

Get hands-on with 1400+ tech skills courses.