Collections Class
The Collections class implements static methods useful when
writing a class that implements Collection
and the iterator
method.
Static Methods
Code String collectionToString(Collection c) #
Returns a string representing the specified collection. If the
collection is a List
, the returned string looks like this:
'[element0, element1, ... elementN]'
. The value returned by its
toString
method is used to represent each element. If the specified
collection is not a list, the returned string looks like this:
{element0, element1, ... elementN}
. In other words, the strings
returned for lists are surrounded by square brackets, while the strings
returned for other collections are surrounded by curly braces.
If the specified collection contains a reference to itself, either
directly or indirectly through other collections or maps, the contained
reference is rendered as '[...]'
if it is a list, or '{...}'
if
it is not. This prevents the infinite regress that would otherwise occur.
So, for example, calling this method on a list whose sole element is a
reference to itself would return '[[...]]'
.
A typical implementation of a collection's toString
method will
simply return the results of this method applied to the collection.
static String collectionToString(Collection c) { var result = new StringBuffer(); _emitCollection(c, result, new List()); return result.toString(); }
Code bool every(Iterable iterable, bool f(o)) #
static bool every(Iterable iterable, bool f(o)) { for (final e in iterable) { if (!f(e)) return false; } return true; }
Code List filter(Iterable source, List destination, bool f(o)) #
static List filter(Iterable source, List destination, bool f(o)) { for (final e in source) { if (f(e)) destination.add(e); } return destination; }
Code void forEach(Iterable iterable, void f(o)) #
static void forEach(Iterable iterable, void f(o)) { for (final e in iterable) { f(e); } }
Code bool isEmpty(Iterable iterable) #
static bool isEmpty(Iterable iterable) { return !iterable.iterator().hasNext(); }