No. Once a String
has been created you cannot change its
data. (Although you can create a new String
that an altered
version of the original.)
There is a division between primitive data types
and the objects.
The division sometimes needs to be crossed.
For each primitive type, there is a corresponding wrapper class.
A wrapper class can be used to convert a primitive data value into an object,
and some type of objects into primitive data.
The table shows primitive types and their wrapper classes.
Case matters,
so byte
and Byte
are different things.
primitive type | Wrapper type |
byte | Byte |
short | Short |
int | Integer |
long | Long |
float | Float |
double | Double |
char | Character |
boolean | Boolean |
As an example, the value 103 could be held in 32 bit section of memory
that is of primitive data type int
.
The same value could be held in an object that is of type Long
.
The object will use many more than 32 bits.
Don't worry if this all seems somewhat pointless to you right now. More will be said about wrapper classes later on when you need to use them.
Is String
a wrapper class?