In data structures, a string is a series of characters that represent text. A string is a sequence of Unicode characters. A string is a reference type, which means it's kept in a heap
There are 2 types of Strings in Data Structure:
Most computer languages treat strings as a separate data type. This means that each string has its own set of operations & properties. They can be defined and modified using string-specific functions and methods.
The following are some of the most common string operations used in programming.
String literals are defined as one or more characters enclosed in single quotes. The default data type for string literals is varchar, although they can be assigned to any character, money, or date data type without the use of a data type conversion function.
Immutability simply means that something cannot be changed or modified. String objects are immutable. Once a String object is formed, its data or state cannot be modified; however, a new String object is generated.
In data structures, "string methods" usually refer to the operations or functions available for manipulating strings. These methods differ depending on the programming language or library used, but common string methods include concatenation, substring extraction, searching for substrings, replacing substrings, converting case (e.g., upper/lowercase), trimming whitespace, splitting strings into substrings using delimiters, and formatting strings.
StringBuilder objects function similarly to String objects, but they can be changed. These objects are handled internally as if they were variable-length arrays holding a string of characters. Method invocations can be used to adjust the sequence's length and content at any time.
In data structures, a StringBuffer is a modifiable sequence of characters used to form strings, providing efficient appending, insertion, deletion, and modification operations while avoiding frequent memory reallocations for dynamic string construction.
Two mutable character sequences used for dynamic string manipulation in data structures are StringBuilder and StringBuffer. StringBuilder is usually quicker and non-synchronized, whereas StringBuffer is synchronized and ensures thread safety at the expense of performance.