add (E value) → void
Adds value
to the end of this list, extending the length by one.
List < int> numbers = [ 1 ] ;
numbers. add ( 2 ) ;
print ( numbers) ;
Appends all objects of iterable
to the end of this list.
List < int> numbers = [ 1 , 2 ] ;
numbers. addAll ( [ 3 , 4 ] ) ;
print ( numbers) ;
Checks whether any element of this iterable satisfies test
.
하나라도 만족하면 true
하나도 만족하지 못하면 false
List < int> numbers = [ 1 , 2 , 3 , 4 ] ;
print ( numbers. any ( ( el) = > el > 3 ) ) ;
print ( numbers. any ( ( el) = > el > 4 ) ) ;
An unmodifiable Map view of this list.
List 의 인덱스를 key 로 하고 객체를 값으로 하는 Map 으로 변환
List < String > terms = [ 'tweet' , 'fat' , 'thin' ] ;
Map < int, String > newTerms = terms. asMap ( ) ;
print ( newTerms) ;
Returns a view of this list as a list of R
instances.
목록의 요소를 특정 유형으로 변환
상위 유형의 목록이 있고 더 구체적인 유형의 목록이 필요할 때 사용
List < Object > dict = [ "tweet" , "fat" , "thin" ] ;
List < String > newDict = dict. cast< String > ( ) ;
print ( newDict) ;
Removes all objects from this list; the length of the list becomes zero.
List < int> numbers = [ 1 , 2 , 3 , 4 ] ;
numbers. clear ( ) ;
print ( numbers) ;
Whether the collection contains an element equal to element
.
List < int> numbers = [ 1 , 2 , 3 , 4 ] ;
print ( numbers. contains ( 1 ) ) ;
print ( numbers. contains ( 5 ) ) ;
Returns the index
th element.
List < int> numbers = [ 1 , 2 , 3 , 4 ] ;
print ( numbers. elementAt ( 2 ) ) ;
Checks whether every element of this iterable satisfies test
.
모두 만족하면 true
하나라도 만족하지 못하면 false
List < int> numbers = [ 1 , 2 , 3 , 4 ] ;
print ( numbers. every ( ( el) = > el > 0 ) ) ;
print ( numbers. every ( ( el) = > el > 1 ) ) ;
Expands each element of this Iterable into zero or more elements.
일반적으로 목록의 각 요소를 반복하고 각 요소에서 다른 유형의 이터러블을 생성하는 방법
List < Map < String , String > > listOfMaps = [
{ 'key1' : 'value1' , 'key2' : 'value2' } ,
{ 'key3' : 'value3' , 'key4' : 'value4' } ,
] ;
Iterable < String > allValues = listOfMaps. expand ( ( map) = > map. values) ;
print ( allValues. toList ( ) ) ;
Iterable < int> count ( int n) sync* {
for ( var i = 1 ; i <= n; i++ ) {
yield i;
}
}
var numbers = [ 1 , 3 , 0 , 2 ] ;
print ( numbers. expand ( count) . toList ( ) ) ;
fillRange (int start, int end, [E? fillValue]) → void
Overwrites a range of elements with fillValue
.
List < int> numbers = List . filled ( 5 , 1 ) ;
numbers. fillRange ( 2 , 4 , 6 ) ;
print ( numbers) ;
firstWhere (bool test(E element), {E orElse()?}) → E
The first element that satisfies the given predicate test
.
List < int> numbers = [ 3 , 5 , 6 , 4 ] ;
int overThree = numbers. firstWhere ( ( el) = > el > 3 ) ;
print ( overThree) ;
fold (T initialValue, T combine(T previousValue, E element)) → T
Reduces a collection to a single value by iteratively combining each element of the collection with an existing value
List < int> numbers = [ 1 , 2 , 3 , 4 ] ;
final result = numbers. fold ( 0 , ( prev, el) = > prev + el) ;
print ( result) ;
Creates the lazy concatenation of this iterable and other
.
List < int> numbers = [ 1 , 2 , 3 , 4 ] ;
final result = numbers. followedBy ( [ 5 , 6 ] ) ;
print ( result. toList ( ) ) ;
forEach (void action(E element)) → void
Invokes action
on each element of this iterable in iteration order.
List < int> numbers = [ 1 , 2 , 3 , 4 ] ;
numbers. forEach ( ( el) = > print ( el + 1 ) ) ;
numbers. forEach ( ( el) {
var result = el + 1 ;
print ( result) ;
} ) ;
Creates an Iterable that iterates over a range of elements.
List < int> numbers = [ 1 , 2 , 3 , 4 ] ;
final ranged = numbers. getRange ( 0 , 3 ) ;
print ( ranged. toList ( ) ) ;
indexOf (E element, [int start = 0]) → int
The first index of element
in this list.
List < int> numbers = [ 1 , 2 , 3 , 4 , 3 , 2 , 1 ] ;
print ( numbers. indexOf ( 3 ) ) ;
The first index in the list that satisfies the provided test
.
List < int> numbers = [ 1 , 2 , 3 , 4 , 3 , 2 , 1 ] ;
print ( numbers. indexWhere ( ( el) = > el > 2 ) ) ;
insert (int index, E element) → void
Inserts element
at position index
in this list.
List < int> numbers = [ 1 , 2 , 3 , 4 ] ;
numbers. insert ( 2 , 5 ) ;
print ( numbers) ;
Inserts all objects of iterable
at position index
in this list.
List < int> numbers = [ 1 , 2 , 3 , 4 ] ;
numbers. insertAll ( 2 , [ 5 , 6 ] ) ;
print ( numbers) ;
Converts each element to a String and concatenates the strings.
List < String > texts = [ "my" , "name" , "is" , "moz" ] ;
print ( texts. join ( " " ) ) ;
The last index of element
in this list.
List < int> numbers = [ 1 , 2 , 3 , 4 , 3 , 2 , 1 ] ;
print ( numbers. lastIndexOf ( 2 ) ) ;
The last index of element
in this list.
List < int> numbers = [ 1 , 2 , 3 , 4 , 3 , 2 , 1 ] ;
print ( numbers. lastIndexWhere ( ( el) = > el > 2 ) ) ;
lastWhere (bool test(E element), {E orElse()?}) → E
The last element that satisfies the given predicate test
.
List < int> numbers = [ 5 , 6 , 7 , 4 , 3 , 2 , 1 ] ;
print ( numbers. lastWhere ( ( el) = > el > 2 ) ) ;
The current elements of this iterable modified by toElement
.
List < int> numbers = [ 1 , 2 , 3 , 4 ] ;
print ( numbers. map ( ( el) = > el + 2 ) . toList ( ) ) ;
Invoked when a nonexistent method or property is accessed.
존재하지 않는 메서드 또는 인스턴스 변수를 사용하려고 시도할 때 사용자 지정 동작을 제공하기 위해 재정의할 수 있는 특수 함수
class MyClass {
@override
noSuchMethod ( Invocation invocation) {
print ( 'You tried to use a non-existent member: ' +
' ${ invocation. memberName } ' ) ;
}
}
reduce (E combine(E value, E element)) → E
Reduces a collection to a single value by iteratively combining elements of the collection using the provided function.
List < int> numbers = [ 1 , 2 , 3 , 4 ] ;
final result = numbers. reduce ( ( value, element) = > value + element) ;
print ( result) ;
Removes the first occurrence of value
from this list.
List < int> numbers = [ 1 , 2 , 3 , 4 , 3 , 2 , 1 ] ;
numbers. remove ( 1 ) ;
print ( numbers) ;
Removes the object at position index
from this list.
List < int> numbers = [ 1 , 2 , 3 , 4 , 3 , 2 , 1 ] ;
final removed = numbers. removeAt ( 5 ) ;
print ( removed) ;
print ( numbers) ;
Removes and returns the last object in this list.
List < int> numbers = [ 1 , 2 , 3 , 4 ] ;
final removed = numbers. removeLast ( ) ;
print ( removed) ;
print ( numbers) ;
Removes a range of elements from the list.
List < int> numbers = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 ] ;
numbers. removeRange ( 2 , 4 ) ;
print ( numbers) ;
Removes all objects from this list that satisfy test
.
List < int> numbers = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 ] ;
numbers. removeWhere ( ( el) = > el < 4 ) ;
print ( numbers) ;
Replaces a range of elements with the elements of replacements
.
List < int> numbers = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 ] ;
numbers. replaceRange ( 3 , 5 , [ 8 , 9 , 10 ] ) ;
print ( numbers) ;
Removes all objects from this list that fail to satisfy test
.
List < int> numbers = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 ] ;
numbers. retainWhere ( ( el) = > el % 2 == 0 ) ;
print ( numbers) ;
Overwrites elements with the objects of iterable
.
List < int> numbers = [ 1 , 2 , 3 , 4 ] ;
numbers. setAll ( 1 , [ 5 , 6 ] ) ;
print ( numbers) ;
Writes some elements of iterable
into a range of this list.
List < int> numbers = [ 1 , 2 , 3 , 4 ] ;
numbers. setRange ( 1 , 4 , [ 5 , 6 , 7 ] ) ;
print ( numbers) ;
Shuffles the elements of this list randomly.
List < int> numbers = [ 1 , 2 , 3 , 4 ] ;
numbers. shuffle ( ) ;
singleWhere (bool test(E element), {E orElse()?}) → E
The single element that satisfies test
.
List < int> numbers = [ 1 , 2 , 3 , 4 ] ;
final result = numbers. singleWhere ( ( el) = > el < 2 ) ;
print ( result) ;
Creates an Iterable that provides all but the first count
elements.
List < int> numbers = [ 1 , 2 , 3 , 4 ] ;
final result = numbers. skip ( 2 ) ;
print ( result. toList ( ) ) ;
Creates an Iterable
that skips leading elements while test
is satisfied.
List < int> numbers = [ 1 , 2 , 3 , 4 ] ;
final result = numbers. skipWhile ( ( el) = > el. isOdd) ;
print ( result. toList ( ) ) ;
sort ([int compare(E a, E b)?]) → void
Sorts this list according to the order specified by the compare
function.
List < int> numbers = [ 1 , 2 , 3 , 4 ] ;
numbers. sort ( ( a, b) = > b. compareTo ( a) ) ;
print ( numbers) ;
Returns a new list containing the elements between start
and end
.
List < int> numbers = [ 1 , 2 , 3 , 4 ] ;
print ( numbers. sublist ( 2 , 4 ) ) ;
Creates a lazy iterable of the count
first elements of this iterable.
List < int> numbers = [ 1 , 2 , 3 , 4 ] ;
print ( numbers. take ( 3 ) . toList ( ) ) ;
Creates a lazy iterable of the leading elements satisfying test
.
List < int> numbers = [ 1 , 2 , 3 , 4 ] ;
print ( numbers. takeWhile ( ( el) = > el. isOdd) . toList ( ) ) ;
Iterable < int> numbers = [ 1 , 2 , 3 , 4 ] ;
print ( numbers. toList ( ) ) ;
Creates a Set containing the same elements as this iterable.
List < int> numbers = [ 1 , 2 , 3 , 4 , 3 , 1 ] ;
print ( numbers. toSet ( ) ) ;
A string representation of this object.
List < int> numbers = [ 1 , 2 , 3 , 4 , 3 , 1 ] ;
print ( numbers. toString ( ) ) ;
Creates a new lazy Iterable with all elements that satisfy the predicate test
.
List < int> numbers = [ 1 , 2 , 3 , 4 , 3 , 1 ] ;
print ( numbers. where ( ( el) = > el. isEven) . toList ( ) ) ;
Creates a new lazy Iterable with all elements that have type T
.
List < Object > numbers = [ 1 , 2 , 'fat' , 4 , 'thin' , 1 ] ;
print ( numbers. whereType< int> ( ) . toList ( ) ) ;