数组 - Arr
## List数组的使用
- 定义数组
```
def list = []
```
```
def list = new ArrayList()
```
- 插入数据
~~~
def list = ["hello","你好"]
list.add("JsDroid")
~~~
~~~
def list = ["hello","你好"]
list[1]="666"
~~~
- 删除数据
~~~
def list = ["hello","你好"]
list.remove(1)
~~~
- 循环输出数据
~~~
def list = ["hello","你好"]
for (def item:list){
print(item)
}
~~~
~~~
def list = ["hello","你好"]
for (def item in list){
print(item)
}
~~~
~~~
def list = ["hello","你好"]
for (int i = 0; i <list.size() ; i++) {
print(list[i])
}
~~~
~~~
def list = ["hello", "你好"]
list.every {
def value ->
print(value)
return true
}
~~~
- 搜索数据
~~~
def list = ["hello", "你好"]
def find = list.find {
def value ->
value=="hello"
}
print find
~~~
## Map表的使用
- 定义表
~~~
def map = [:]
~~~
~~~
def map = new HashMap()
~~~
- 添加数据
~~~
def map = [:]
map.name = "who"
~~~
~~~
def map = [:]
map["name"] = "who"
~~~
~~~
def map = [:]
map.put("name", "who")
~~~
- 读取数据
~~~
def map = [name:"who",sex:"boy"]
print map.name
~~~
- 遍历数据
~~~
def map = [name:"who",sex:"boy"]
map.each {
k, v ->
print(k+"==>"+v)
}
~~~