Dart String Comparator

Yes, == is the way to test if two Strings are equal (contain exclusively the same sequence of characters). The last line of your code evaluates to true.


Strings are immutable objects, which means you can create them but you can't change them. You can of course build a new string out of other strings, but once created, the string's contents are fixed.

This is an optimization, as two strings with the same characters in the same order can be the same object.

String rubi = 'good';
String ore = 'good';

print(rubi == ore); // true, contain the same characters
print(identical(rubi, ore)); // true, are the same object in memory

Tags:

Dart