- Dart Programming - HTML DOM
- Dart Programming - Unit Testing
- Dart Programming - Concurrency
- Dart Programming - Async
- Dart Programming - Libraries
- Dart Programming - Typedef
- Dart Programming - Debugging
- Dart Programming - Exceptions
- Dart Programming - Packages
- Dart Programming - Generics
- Dart Programming - Collection
- Dart Programming - Object
- Dart Programming - Classes
- Dart Programming - Interfaces
- Dart Programming - Functions
- Dart Programming - Enumeration
- Dart Programming - Runes
- Dart Programming - Symbol
- Dart Programming - Map
- Dart Programming - Lists
- Dart Programming - Lists
- Dart Programming - Boolean
- Dart Programming - String
- Dart Programming - Numbers
- Dart Programming - Decision Making
- Dart Programming - Loops
- Dart Programming - Operators
- Dart Programming - Variables
- Dart Programming - Data Types
- Dart Programming - Syntax
- Dart Programming - Environment
- Dart Programming - Overview
- Dart Programming - Home
Dart Programming Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Dart Programming - Collection
Dart, unpke other programming languages, doesn’t support arrays. Dart collections can be used to reppcate data structures pke an array. The dart:core pbrary and other classes enable Collection support in Dart scripts.
Dart collections can be basically classified as −
Sr.No | Dart collection & Description |
---|---|
1 | A List is simply an ordered group of objects. The dart:core pbrary provides the List class that enables creation and manipulation of psts. Fixed Length List − The pst’s length cannot change at run-time. Growable List − The pst’s length can change at run-time. |
2 | Set represents a collection of objects in which each object can occur only once. The dart:core pbrary provides the Set class to implement the same. |
3 | The Map object is a simple key/value pair. Keys and values in a map may be of any type. A Map is a dynamic collection. In other words, Maps can grow and shrink at runtime. The Map class in the dart:core pbrary provides support for the same. |
4 | A Queue is a collection that can be manipulated at both ends. Queues are useful when you want to build a first-in, first-out collection. Simply put, a queue inserts data from one end and deletes from another end. The values are removed / read in the order of their insertion. |
Iterating Collections
The Iterator class from the dart:core pbrary enables easy collection traversal. Every collection has an iterator property. This property returns an iterator that points to the objects in the collection.
Example
The following example illustrates traversing a collection using an iterator object.
import dart:collection ; void main() { Queue numQ = new Queue(); numQ.addAll([100,200,300]); Iterator i= numQ.iterator; while(i.moveNext()) { print(i.current); } }
The moveNext() function returns a Boolean value indicating whether there is a subsequent entry. The current property of the iterator object returns the value of the object that the iterator currently points to.
This program should produce the following output −
100 200 300Advertisements