Programming in Dart: Fundamentals

Apr 26 2022 Dart 2.15, DartPad, DartPad

Part 2: Introducing Collections & Null Safety

15. Combine Lists

Episode complete

Play next episode

Save for later
About this episode
See versions
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 14. Create a Conditional List Next episode: 16. Conclusion

This video Combine Lists was last updated on Apr 26 2022

Heads up... You've reached locked video content where the transcript will be shown as obfuscated text.

You can unlock the rest of this video course, and our entire catalogue of books and videos, with a Professional subscription.

Often times, you’ll want to combine lists and with Dart, this is actually quite easy to do. We use the plus operator between two lists, and basically, we add the two lists together. So Dart makes this operation really easy to do.

var yourCards = ['8♦️', '3♣️', 'J♠️'];
var myCards = ['10❤️', 'Q♦️', '2♠️'];
var bonusCard = 'A♠️';
var cards = [yourCards, myCards, bonusCard];
var cards = [...yourCards, ...myCards, bonusCard];
 List<String>? emptyHand = null; 
var cards = [...yourCards, ...myCards, bonusCard, ...emptyHand];
var cards = [...yourCards, ...myCards, bonusCard, ...emptyHand];