Built-in types, collections, and other core functionality for every Dart program.

This library is automatically imported.

Some classes in this library, such as String and num, support Dart's built-in data types. Other classes, such as List and Map, provide data structures for managing collections of objects. And still other classes represent commonly used types of data such as URIs, dates and times, and errors.

Numbers and booleans

int and double provide support for Dart's built-in numerical data types: integers and double-precision floating point numbers, respectively. An object of type bool is either true or false. Variables of these types can be constructed from literals:

int meaningOfLife = 42;
double valueOfPi  = 3.141592;
bool visible      = true;

Strings and regular expressions

A String is immutable and represents a sequence of characters.

String shakespeareQuote = "All the world's a stage, ...";

StringBuffer provides a way to construct strings efficiently.

StringBuffer moreShakespeare = new StringBuffer();
moreShakespeare.write('And all the men and women ');
moreShakespeare.write('merely players; ...');

The String and StringBuffer classes implement string concatenation, interpolation, and other string manipulation features.

String philosophy = 'Live on ';
String get palindrome => philosophy + philosophy.split('').reversed.join();

RegExp implements Dart regular expressions, which provide a grammar for matching patterns within text. For example, here's a regular expression that matches a string of one or more digits:

var numbers = new RegExp(r'\d+');

Dart regular expressions have the same syntax and semantics as JavaScript regular expressions. See ecma-international.org/ecma-262/5.1/#sec-15.10 for the specification of JavaScript regular expressions.

Collections

The dart:core library provides basic collections, such as List, Map, and Set.

A List is an ordered collection of objects, with a length. Lists are sometimes called arrays. Use a List when you need to access objects by index.

List superheroes = [ 'Batman', 'Superman', 'Harry Potter' ];

A Set is an unordered collection of unique objects. You cannot get an item by index (position). Adding a duplicate item has no effect.

Set villains = new Set();
villains.add('Joker');
villains.addAll( ['Lex Luther', 'Voldemort'] );

A Map is an unordered collection of key-value pairs. Maps are sometimes called associative arrays because maps associate a key to some value for easy retrieval. Keys are unique. Use a Map when you need to access objects by a unique identifier.

Map sidekicks = { 'Batman': 'Robin',
                  'Superman': 'Lois Lane',
                  'Harry Potter': 'Ron and Hermione' };

In addition to these classes, dart:core contains Iterable, an interface that defines functionality common in collections of objects. Examples include the ability to run a function on each element in the collection, to apply a test to each element, to retrieve an object, and to determine length.

Iterable is implemented by List and Set, and used by Map for its keys and values.

For other kinds of collections, check out the dart:collection library.

Date and time

Use DateTime to represent a point in time and Duration to represent a span of time.

You can create DateTime objects with constructors or by parsing a correctly formatted string.

DateTime now = new DateTime.now();
DateTime berlinWallFell = new DateTime(1989, 11, 9);
DateTime moonLanding = DateTime.parse("1969-07-20");

Create a Duration object specifying the individual time units.

Duration timeRemaining = new Duration(hours:56, minutes:14);

In addition to DateTime and Duration, dart:core contains the Stopwatch class for measuring elapsed time.

Uri

A Uri object represents a uniform resource identifier, which identifies a resource on the web.

Uri dartlang = Uri.parse('http://dartlang.org/');

Errors

The Error class represents the occurrence of an error during runtime. Subclasses of this class represent specific kinds of errors.

Other documentation

For more information about how to use the built-in types, refer to Built-in Types in Chapter 2 of Dart: Up and Running.

Also, see dart:core - Numbers, Collections, Strings, and More for more coverage of classes in this package.

The Dart Language Specification provides technical details.

Constants

deprecated Deprecated

Marks a feature as Deprecated until the next release.

const Deprecated("next release")
override Object

The annotation @override marks an instance member as overriding a superclass member with the same name.

const _Override()
proxy Object

The annotation @proxy marks a class as implementing members dynamically through noSuchMethod.

const _Proxy()

Typedefs

Comparator(T a, T b) int

The signature of a generic comparison function.

Functions

identical(Object a, Object b) bool

Check whether two references are to the same object.

identityHashCode(Object object) int

Returns the identity hash code of object.

print(Object object) → void

Prints a string representation of the object to the console.

Classes

BidirectionalIterator

An Iterator that allows moving backwards as well as forwards.

bool

The reserved words true and false denote objects that are the only instances of this class.

Comparable

Interface used by types that have an intrinsic ordering.

DateTime

An instant in time, such as July 20, 1969, 8:18pm GMT.

Deprecated

The annotation @Deprecated('expires when') marks a feature as deprecated.

double

A double-precision floating point number.

Duration

A span of time, such as 27 days, 4 hours, 12 minutes, and 3 seconds.

Expando

An Expando allows adding new properties to objects.

Function

The base class for all function types.

int

An arbitrarily large integer.

Invocation

Representation of the invocation of a member on an object.

Iterable

A collection of values, or "elements", that can be accessed sequentially.

Iterator

An interface for getting items, one at a time, from an object.

List

An indexable collection of objects with a length.

Map

An collection of key-value pairs, from which you retrieve a value using its associated key.

Match

A result from searching within a string.

Null

The reserved word null denotes an object that is the sole instance of this class.

num

An integer or floating-point number.

Object

The base class for all Dart objects.

Pattern

An interface for basic searches within strings.

RegExp

A regular expression pattern.

RuneIterator

Iterator for reading runes (integer Unicode code points) out of a Dart string.

Runes

The runes (integer Unicode code points) of a String.

Set

A collection of objects in which each object can occur only once.

Sink

A generic destination for data.

StackTrace

An interface implemented by all stack trace objects.

Stopwatch

A simple stopwatch interface to measure elapsed time.

String

A sequence of characters.

StringBuffer

A class for concatenating strings efficiently.

StringSink

Symbol

Opaque name used by mirrors, invocations and Function.apply.

Type

Runtime representation of a type.

Uri

A parsed URI, such as a URL.

UriData

A way to access the structure of a data: URI.

Exceptions / Errors

AbstractClassInstantiationError

Error thrown when trying to instantiate an abstract class.

ArgumentError

Error thrown when a function is passed an unacceptable argument.

AssertionError

Error thrown by the runtime system when an assert statement fails.

CastError

Error thrown by the runtime system when a cast operation fails.

ConcurrentModificationError

Error occurring when a collection is modified during iteration.

CyclicInitializationError

Error thrown when a lazily initialized variable cannot be initialized.

Error

Error objects thrown in the case of a program failure.

Exception

A marker interface implemented by all core library exceptions.

FallThroughError

Error thrown when control reaches the end of a switch case.

FormatException

Exception thrown when a string or some other data does not have an expected format and cannot be parsed or processed.

IndexError

A specialized RangeError used when an index is not in the range 0..indexable.length-1.

IntegerDivisionByZeroException

NoSuchMethodError

Error thrown by the default implementation of noSuchMethod on Object.

NullThrownError

Error thrown when attempting to throw null.

OutOfMemoryError

RangeError

Error thrown due to an index being outside a valid range.

StackOverflowError

StateError

The operation was not allowed by the current state of the object.

TypeError

Error thrown by the runtime system when a type assertion fails.

UnimplementedError

Thrown by operations that have not been implemented yet.

UnsupportedError

The operation was not allowed by the object.