Robotics C++ Physics II AP Physics B Electronics Java Astronomy Other Courses Summer Session  

Objects of the String Class Are Immutable

  Introduction

  Example 1

  Example 2

  Example 3

 

Introduction

 

The String class is immutable, so that once it is created a String object cannot be changed. The String class has a number of methods, some of which are discussed in the text, that appear to modify strings. Since strings are immutable, what these methods really do is create and return a new string that contains the result of the operation.

 

This is contrasted with the use of strings in C++ where the individual elements can be changed by traversing the array used to hold the string.