list common properties and methods
common property
1,length gets the length of list
main() {
var list = ['red','yellow','pink'];
print(list.length);
}
2, judge whether it is empty
main() {
var list = ['red','yellow','pink'];
print(list.isEmpty);
}
3, not null
main() {
var list = ['red','yellow','pink'];
print(list.isNotEmpty);
}
4, the array flips
main() {
var list = ['red','yellow','pink'];
print(list.reversed.toList());
}
(pink, yellow, red)
common method
1, add data
main() {
var list = ['red','yellow','pink'];
list.add("green");
print(list);
}
[red, yellow, pink, green]
2, find data indexOf, find return index, can’t find return -1
main() {
var list = ['red','yellow','pink'];
var res = list.indexOf('yellow');
print(res);
}
1
3, removed data (‘ value ‘),removeAt(index)
main() {
var list = ['red','yellow','pink'];
list.remove('yellow');
list.removeAt(1);
print(list);
}
[red]
4, modify data fillRange(start,end,value) without end
main() {
var list = ['red','yellow','pink'];
list.fillRange(1, 2,'green');
print(list);
}
[red, green, pink]
5, insert data insert(index,value) to the specified position. Insert
from index
main() {
var list = ['red','yellow','pink'];
list.insert(1, 'green');
print(list);
}
[red, green, yellow, pink]
main() {
var list = ['red','yellow','pink'];
list.insertAll(1, ['green','white']);
print(list);
}
[red, green, white, yellow, pink]
6, convert to string join(‘, ‘), instead of the original list
main() {
var list = ['red','yellow','pink'];
var str = list.join(',');
print(str);
}
red,yellow,pink
7, convert string to array split(‘ – ‘), do not change the original string
main() {
var str = 'red-yellow-pink';
var list = str.split('-');
print(list);
print(str);
}
[red, yellow, pink]
red-yellow-pink
8, for(var item in list) loop list
main() {
var list = ['red','yellow','pink'];
for(var item in list) {
print(item);
}
}
red
yellow
pink
9,map loop list
main() {
var list = [1,2,3,4];
var newList = list.map((value) => value * 2);
print(newList.toList());
}
10, see if the set satisfies some condition any
main() {
var list = ['red','yellow','pink'];
var f = list.any((value) => value == 'red');
print(f);
print(list);
}
11, through the set can not add repeated collection, so can not get
through the index
main() {
var set = new Set();
set.add('red');
set.add('yellow');
set.add('pink');
set.add('red');
print(set.toList());
}
[red, yellow, pink]
maps type common properties and methods
1, get all keys
main() {
var person = {
'name':'张三',
'age':20,
};
print(person.keys.toList());
}
[name, age]
2, get all values
main() {
var person = {
'name':'张三',
'age':20,
};
print(person.values.toList());
}
3, determine whether the attribute isEmpty isEmpty
main() {
var person = {
'name':'张三',
'age':20,
};
print(person.isEmpty);
}
false
common method
1, remove the specified key data (key)
main() {
var person = {
'name':'张三',
'age':20,
};
person.remove('name');
print(person);
}
{age: 20}
2, addAll({‘ key ‘:’ value ‘})
main() {
var person = {
'name':'张三',
'age':20,
};
person.addAll({
'sex':'男',
});
print(person);
}
{name: 张三, age: 20, sex: 男}
3, check to see if the fields are in the map containsKey(key), return true/false does not change the original pair like
main() {
var person = {
'name':'张三',
'age':20,
};
var boo = person.containsKey('name');
print(boo);
}
true
blog address
related documents
github document address
Read More:
- Common problems of shadow map in OpenGL
- Common errors and modification methods of findbug
- Struts 2 encapsulates form data into list and map sets
- Several common methods of inserting pictures into latex documents
- Map to vector pair map.second sort
- Error handling when ABP specifies map object during map operation
- Methods of modifying index and columns names by dataframe in pandas
- Android 9 (P) recovery upgrade Map of ‘@/cache/recovery/block.map’ failed problem analysis guide
- Easynvr operation log reports an error. Fatal error: concurrent map read and map write troubleshooting
- Pre initialization of list content and length in Python
- [go] solve the fatal error of go: concurrent map writes map non concurrent security
- The attribute error: he has no attributes.
- Translate() and maketrans() methods of string in Python
- Vue calculates attributes and passes parameters to the computed method
- Error: php56w-common conflicts with php-common-5.3.3-48.el6_ 8.x86_ 64
- [Vue warn]: Error in nextTick: “TypeError: Cannot read property ‘map‘ of null“
- Three methods of referencing DLL in Visual Studio 2015
- Several methods of deleting all empty lines in text under Linux
- Methods of compiling and installing ffmpeg and libx264 in Linux