Skip to content

Instantly share code, notes, and snippets.

@Simpler1
Created October 18, 2022 18:49
Show Gist options
  • Save Simpler1/bcba709058741eba73155faa35a95c60 to your computer and use it in GitHub Desktop.
Save Simpler1/bcba709058741eba73155faa35a95c60 to your computer and use it in GitHub Desktop.
Dart Lists
void main() {
final List list1 = ['zero', 'one', 'two', 'three'];
final List list2 = list1; // <- Create a new reference to the same list
list2[1] = 'five';
print('$list1 $list2');
final List list3 = ['nine', 'ten', 'eleven'];
final List list4 = List.from(list3); // <- Create a brand new list
list4[1] = 'twenty';
print('$list3 $list4');
// Lists should be final even though their contents can change.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment