Skip to content

Instantly share code, notes, and snippets.

@leonus96
Created October 19, 2023 02:15
Show Gist options
  • Save leonus96/280a30251c5d221db36dc787e5df7136 to your computer and use it in GitHub Desktop.
Save leonus96/280a30251c5d221db36dc787e5df7136 to your computer and use it in GitHub Desktop.
listas y sets
void main() {
/// LISTAS:
/// Una lista es una colección ordenada de elementos que
/// pueden ser del mismo tipo o de tipos diferentes.
/// Sintaxis: List nombre = [];
// final List<String> heroes = ['Superman', 'Spiderman', 'Flash'];
/// Imprimir:
/// print(heroes);
/// Acceder a elementos:
/// final ultimoNombreHeroe = heroes[2];
/// print(ultimoNombreHeroe);
/// Modificar elementos de la lista:
/// heroes[2] = 'Chapulin';
/// heroes[0] = 'Cap. America';
/// print(heroes);
/// Agregar elementos:
/// heroes.add('Antman');
/// heroes.add('Chapulin');
/// print(heroes);
/// Remover elementos:
/// heroes.removeAt(0);
/// print(heroes);
/// Longitud
// print(heroes.length);
/// SETS:
/// un conjunto (set) es una colección de elementos únicos y
/// desordenados, lo que significa que no puede contener
/// elementos duplicados y no tiene un orden predefinido.
/// Sintaxis: Set nombre = {}
/// final Set<String> heroes = {'Superman', 'Antman', 'Spiderman'};
/// Imprimir un set
/// print(heroes);
/// Agregamos elementos:
/// heroes.add('Chapulin');
/// heroes.add('Superman');
/// Removemos elementos:
/// heroes.remove('Antman');
/// Verificar si un elemento esta dentro del set:
/// final bool estaHulk = heroes.contains('Hulk');
/// Imprimir tamaño:
/// print(heroes.length);
/// Convertir Set -> List o List -> Set
/// final List<String> alumnos = ['Alexander', 'Claudia', 'Claudia', 'Katerin', 'Carlos F', 'Katerin'];
/// print(alumnos);
/// final Set<String> setAlumnos = alumnos.toSet();
/// print(setAlumnos);
/// final List<String> alumnosSinDup = setAlumnos.toList();
/// print(alumnosSinDup);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment