How acces to the values of a Set


I’am a begginer in Dart and i dont know how to acces to the values of the next Set

Set mySet = Set.from(['Please', 'Help', 'Me']);


I didn’t get the clarity of what you mean by accessing next set but, you can access your current set data in following ways.

Set mySet = Set.from(['Please', 'Help', 'Me']); // declaration.

Accessing through index

print('mySet.elementAt(0): ${mySet.elementAt(0)}');
print('mySet.elementAt(1): ${mySet.elementAt(1)}');
print('mySet.elementAt(2): ${mySet.elementAt(2)}');

Iterating over set.

mySet.forEach((value) => {print(value)});

Logging to see data stored in current set.

print('mySet: ${mySet.toString()}');

Answered By – Kalpesh Kundanani

Answer Checked By – Mildred Charles (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *