Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Flutter how to get "content of list" using a "list of index"?

List a = [3,5,7]
List b = [apple, banana, cake, coke, car, train, dog, paper]

output: coke, train, paper

Any function in Dart can achieve this ?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Try this

  List<int> a = [3, 5, 7];
  List<String> b = [
    'apple',
    'banana',
    'cake',
    'coke',
    'car',
    'train',
    'dog',
    'paper'
  ];

  List newList = a.map((e) => b[e]).toList();

  print(newList);

More info on map

https://api.dart.dev/stable/2.16.2/dart-core/Iterable/map.html

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading