From 0626b1e346778c2d0d86c4d40d82000223682e5b Mon Sep 17 00:00:00 2001 From: Muntazir-sd Date: Fri, 19 Dec 2025 20:50:27 +0530 Subject: [PATCH] Add Dart Map .cast() term entry --- content/dart/concepts/map/terms/cast/cast.md | 47 ++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 content/dart/concepts/map/terms/cast/cast.md diff --git a/content/dart/concepts/map/terms/cast/cast.md b/content/dart/concepts/map/terms/cast/cast.md new file mode 100644 index 00000000000..d685753a4fb --- /dev/null +++ b/content/dart/concepts/map/terms/cast/cast.md @@ -0,0 +1,47 @@ +--- +Title: '.cast()' +Description: 'Returns a new Map with the same entries but with different key and value types.' +Subjects: + - 'Computer Science' + - 'Data Science' +Tags: + - 'Dart' + - 'Map' + - 'Methods' +CatalogContent: + - 'learn-dart' + - 'paths/computer-science' +--- + +In Dart, the **`.cast()`** method returns a new `Map` containing the same key–value pairs as the original map, but with the specified key and value types. The returned map performs type checks when accessing or modifying its entries. + +This method is commonly used when working with dynamically typed maps that need to be treated as a map with specific types. + +## Syntax + +```pseudo +mapVariable.cast() +``` + +`mapVariable` is the `Map` object whose entries are cast to new types. + +## Example + +```dart +void main() { + Map rawData = { + 'Alice': 90, + 'Bob': 85, + }; + + Map scores = rawData.cast(); + + print(scores); +} +``` + +**Output:** + +```shell +{Alice: 90, Bob: 85} +```