Junior — Middle
Is a string in programming a fixed-length data type or can it be changed after creation?
sobes.tech AI
Answer from AI
In most programming languages, a string is a data type with immutable length after creation. This means that once a string is created, its content and length cannot be changed directly.
If you need to modify a string, a new string with the changed content is created. For example, in Java or Python, strings are immutable.
Example in Java:
String s = "hello";
s = s + " world"; // a new string "hello world" is created
If a mutable sequence of characters is needed, special classes are used, such as StringBuilder in Java, which allows modifying the content without creating new objects.