The String class allows you to use and manipulate strings of text in more complex ways than character arrays do. You can concatenate Strings, append to them, search for and replace substrings, and more. It takes more memory than a simple character array, but it is also more useful.
For reference, character arrays are referred to as strings with a small s, and instances of the String class are referred to as Strings with a capital S. Note that constant strings, specified in "double quotes" are treated as char arrays, not instances of the String class.
String methods store the contents of the string as a heap allocated block of memory, such as with
malloc(). As such, using a large number of long-lived strings can cause heap fragmentation, especially if you have used most of the available RAM.
Because the contents of the string are stored separately from the object itself, and the string is variable length, you cannot pass
String objects to
EEPROM.put(). You can only used fixed-length character arrays with
Likewise, you should not declare a
String global variable as
retained (saved in battery-backed SRAM), as the object will be retained, but the contents of the string will not, which is probably not what you intended.