Created with <3 with dartpad.dev.
Created
October 19, 2023 02:46
-
-
Save leonus96/8f2b7e0294a7eab21600aa3d5144140f to your computer and use it in GitHub Desktop.
mapas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
/// MAPs | |
/// un mapa (map) es una colección de pares | |
/// clave-valor, donde cada clave es única y | |
/// está asociada a un valor. | |
/// Sintaxis: Map nombre = {key: value}; | |
/// final Map<int, String> dias = { | |
/// 1: 'Lunes', | |
/// 2: 'Martes', | |
/// 3: 'Miercoles', | |
/// 4: 'Jueves', | |
/// 5: 'Viernes', | |
/// 6: 'Sabado', | |
/// 7: 'Domingo', | |
/// }; | |
/// Imprime un mapa | |
/// print(dias); | |
Map<String, int> edadesAlumnos = { | |
'Miguel': 67, | |
'Carlos': 98, | |
'Joseph': 120, | |
'Katerin': 23, | |
}; | |
/// Accede al valor de un mapa: | |
/// print(edadesAlumnos['Carlos']); | |
/// Agregar un nuevo elemento: | |
/// edadesAlumnos['Rosa'] = 25; | |
/// Modificar elementos: | |
/// edadesAlumnos['Carlos'] = 18; | |
/// Remover elementos: | |
/// edadesAlumnos.remove('Joseph'); | |
/// Verificar si una clave existe en el mapa: | |
/// final bool estaEddie = edadesAlumnos.containsKey('Eddie'); | |
/// print(estaEddie); | |
/// Lista de claves: | |
/// final List<String> alumnos = edadesAlumnos.keys.toList(); | |
/// print(alumnos); | |
/// Lista de valores: | |
/// final List<int> edades = edadesAlumnos.values.toList(); | |
/// print(edades); | |
/// OTRO EJEMPLO DE MAP: | |
/// final Map<String, dynamic> heroe = { | |
/// 'nombre': 'Flash', | |
/// 'poder': 'velocidad', | |
/// 'edad': 25, | |
/// }; | |
///print(heroe); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment