String Class Diagram

 

 

Ancestor class specifications:

java.lang.Object
java.lang.Comparable

String Class Specification

            Invariant

                        A String object

-       is a sequence of zero or more char values

-       is immutable (cannot be altered once it is instantiated)

 

            String constant

A String constant consists of any sequence of char constants without enclosing single quotes.  The entire string constant must be preceded and followed by double quotation marks (").

 

            Constructor Methods

public String(String s)

      post:  A new String object is created and the sequence of characters is the same as s

 

            Other Methods

public char charAt(int p)

      pre:   p < length()

      post:  result == the char at position p from this string (note that zero is the position

                                    of the leftmost character)

 

public int length()

      post:  result == the number of characters in this string

 

public String toUpperCase()

      post:  result ==  this string with every lowercase letter replaced by the corresponding

                         uppercase letter

 

public String toLowerCase()

      post:    result ==  this string with every uppercase letter replaced by the corresponding

                         lowercase letter

 

            Infix Operator

                              +      evaluates to a string consisting of its two operand strings concatenated (joined).