Strings
Strings are immutable, which is a fancy way of saying that string operations create new strings instead of modifying existing strings. Strings (like numbers) are hashable, meaning that unique objects have unique hash codes to tell them apart. If we assign a variable to a variable holding a string, both will have the hash code because they are the same object.
primitives/strings.dart | |
| var str1 = "foo", |
| str2 = str1; |
| str1.hashCode; // 596015325 |
| str2.hashCode; // 596015325 |
But if we modify the first string, the result will be an entirely new object while the copy continues to point to the original string.
primitives/string_concat.dart | |
| str1 = str1 + "bar"; |
| |
| str1.hashCode; // 961740263 |
| str2.hashCode; // 596015325 |
Dart ...
Get Dart 1 for Everyone now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.