Movatterモバイル変換


[0]ホーム

URL:


menu
  1. Dart
  2. dart:core
  3. Map<K,V>
  4. update abstract method
update
description

update abstract method

Vupdate(
  1. Kkey,
  2. Vupdate(
    1. Vvalue
    ), {
  3. VifAbsent()?,
})

Updates the value for the providedkey.

Returns the new value associated with the key.

If the key is present, invokesupdate with the current valueand stores the new value in the map.

If the key is not present andifAbsent is provided, callsifAbsentand adds the key with the returned value to the map.

If the key is not present,ifAbsent must be provided.

final planetsFromSun = <int, String>{1: 'Mercury', 2: 'unknown',  3: 'Earth'};// Update value for known key value 2.planetsFromSun.update(2, (value) => 'Venus');print(planetsFromSun); // {1: Mercury, 2: Venus, 3: Earth}final largestPlanets = <int, String>{1: 'Jupiter', 2: 'Saturn',  3: 'Neptune'};// Key value 8 is missing from list, add it using [ifAbsent].largestPlanets.update(8, (value) => 'New', ifAbsent: () => 'Mercury');print(largestPlanets); // {1: Jupiter, 2: Saturn, 3: Neptune, 8: Mercury}

Implementation

V update(K key, V update(V value), {V ifAbsent()?});
  1. Dart
  2. dart:core
  3. Map<K,V>
  4. update abstract method
Map class

[8]ページ先頭

©2009-2025 Movatter.jp