OLD | NEW |
---|---|
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 part of dart.core; | 5 part of dart.core; |
6 | 6 |
7 /** | 7 /** |
8 * An indexable collection of objects with a length. | 8 * An indexable collection of objects with a length. |
9 * | 9 * |
10 * Subclasses of this class implement different kinds of lists. | 10 * Subclasses of this class implement different kinds of lists. |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
185 /** | 185 /** |
186 * Returns an [Iterable] of the objects in this list in reverse order. | 186 * Returns an [Iterable] of the objects in this list in reverse order. |
187 */ | 187 */ |
188 Iterable<E> get reversed; | 188 Iterable<E> get reversed; |
189 | 189 |
190 /** | 190 /** |
191 * Sorts this list according to the order specified by the [compare] function. | 191 * Sorts this list according to the order specified by the [compare] function. |
192 * | 192 * |
193 * The [compare] function must act as a [Comparator]. | 193 * The [compare] function must act as a [Comparator]. |
194 * | 194 * |
195 * List<String> numbers = ['one', 'two', 'three', 'four']; | 195 * List<String> numbers = ['two', 'three', 'four']; |
196 * // Sort from shortest to longest. | 196 * // Sort from shortest to longest. |
197 * numbers.sort((x, y) => x.length.compareTo(y.length)); | 197 * numbers.sort((a, b) => a.length.compareTo(b.length)); |
198 * numbers.join(', '); // 'one, two, four, three' | 198 * print(numbers); // [two, four, three] |
199 * | 199 * |
200 * The default List implementations use [Comparable.compare] if | 200 * The default List implementations use [Comparable.compare] if |
201 * [compare] is omitted. | 201 * [compare] is omitted. |
202 * | 202 * |
203 * List<int> nums = [13, 2, -11]; | 203 * List<int> nums = [13, 2, -11]; |
204 * nums.sort(); | 204 * nums.sort(); |
205 * nums.join(', '); // '-11, 2, 13' | 205 * print(nums); // [-11, 2, 13] |
206 * | |
207 * A [Comparator] may compare objects as equal (return zero), even if they | |
208 * are distinct objects. | |
209 * The sort function is not guaranteed to be stable, so distinct objects | |
210 * that compare as equal may occur in any order in the result: | |
211 * | |
212 * List<String> numbers = ['one', 'two', 'three', 'four']; | |
213 * numbers.sort((a, b) => a.length.compareTo(b.length)); | |
214 * print(numbers); // [one, two, four, three] OR [two, one, four, three] | |
eernst
2015/12/08 09:02:08
It is slightly confusing that `print(numbers)` omi
| |
206 */ | 215 */ |
207 void sort([int compare(E a, E b)]); | 216 void sort([int compare(E a, E b)]); |
208 | 217 |
209 /** | 218 /** |
210 * Shuffles the elements of this list randomly. | 219 * Shuffles the elements of this list randomly. |
211 */ | 220 */ |
212 void shuffle([Random random]); | 221 void shuffle([Random random]); |
213 | 222 |
214 /** | 223 /** |
215 * Returns the first index of [element] in this list. | 224 * Returns the first index of [element] in this list. |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
471 * as values. The `Map.keys` [Iterable] iterates the indices of this list | 480 * as values. The `Map.keys` [Iterable] iterates the indices of this list |
472 * in numerical order. | 481 * in numerical order. |
473 * | 482 * |
474 * List<String> words = ['fee', 'fi', 'fo', 'fum']; | 483 * List<String> words = ['fee', 'fi', 'fo', 'fum']; |
475 * Map<int, String> map = words.asMap(); | 484 * Map<int, String> map = words.asMap(); |
476 * map[0] + map[1]; // 'feefi'; | 485 * map[0] + map[1]; // 'feefi'; |
477 * map.keys.toList(); // [0, 1, 2, 3] | 486 * map.keys.toList(); // [0, 1, 2, 3] |
478 */ | 487 */ |
479 Map<int, E> asMap(); | 488 Map<int, E> asMap(); |
480 } | 489 } |
OLD | NEW |