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

Next
About this episode
Leave a rating/review
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 14. Create a Conditional List Next episode: 16. Conclusion

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

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

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];
print(cards);
var cards = [...yourCards, ...myCards, bonusCard];
 List<String>? emptyHand = null; 
var cards = [...yourCards, ...myCards, bonusCard, ...emptyHand];
var cards = [...yourCards, ...myCards, bonusCard, ...emptyHand];