asdtiang的博客 感谢blogjava提供的博客交流平台

 `def weekDays = ["Mon","Tue","Wed","Thu","Fri"];`

 `def weekDays: String[] = ["Mon","Tue","Wed","Thu","Fri"];`

 `def days = [weekDays, ["Sat","Sun"]];`

 `def days = ["Mon","Tue","Wed","Thu","Fri","Sat","Sun"];`

```def nums = [1..100];

```

 `def nums = [1,2,3,4,5];`

 `def numsGreaterThanTwo = nums[n | n > 2];`

1. 新创建的序列存储在 `numsGreaterThanTwo` 中。
2. 代码 `nums[n | n > 2];` 中标记为粗体的部分指定要从中复制项的原始序列。在我们的示例中，`nums` 是原始序列的名称。
3. 这会选择 `nums` 中的项，并按顺序返回一个由使表达式为 true 的项构成的新序列。
4. "|" 字符用来在视觉上将变量 "n" 与代码的其余部分隔开：```nums[n | n > 2];```
5. 代码 `nums[n | n > 2];` 中标记为粗体的部分定义一个布尔表达式，该表达式指定将当前项复制到新序列中时需要满足的条件。

 ```def days = ["Mon","Tue","Wed","Thu","Fri","Sat","Sun"]; println(days[0]); println(days[1]); println(days[2]); println(days[3]); println(days[4]); println(days[5]); println(days[6]);```

 ```Mon Tue Wed Thu Fri Sat Sun```

 `sizeof days`

 ```def days = ["Mon","Tue","Wed","Thu","Fri","Sat","Sun"]; println(sizeof days);```

`insert` 关键字可用于在序列中特定项的前面后面插 入一个项。

 `var days = ["Mon"];`

 `insert "Tue" into days;`

 ```insert "Fri" into days; insert "Sat" into days; insert "Sun" into days;```

 `insert "Thu" before days[2];`

 `insert "Wed" after days[1];`

 `delete "Sun" from days;`

 `delete days[0];`

 `delete days;`

 ```var nums = [1..5]; reverse nums; // returns [5, 4, 3, 2, 1]```

 ```def seq1 = [1,2,3,4,5]; def seq2 = [1,2,3,4,5]; println(seq1 == seq2);```

 ```def seq1 = [1,2,3,4,5]; def seq2 = [1,2,3,4,5,6]; println(seq1 == seq2);```

 ```def seq1 = [1,2,3,4,5]; def seq2 = [1,3,2,4,5]; println(seq1 == seq2);```

seq[a..b]

 ```def days = ["Mon","Tue","Wed","Thu","Fri","Sat","Sun"]; def weekend = days[5..6];```

seq[a..<b]

 ```def days = ["Mon","Tue","Wed","Thu","Fri","Sat","Sun"]; def weekdays = days[0..<5];```

seq[a..]

 ```def days = ["Mon","Tue","Wed","Thu","Fri","Sat","Sun"]; def weekend = days[5..];```

seq[a..<]

 ```def days = ["Mon","Tue","Wed","Thu","Fri","Sat","Sun"]; def days2 = days[0..<];```

```
```

 只有注册用户登录后才能发表评论。 网站导航: 相关文章:

posts - 80, comments - 24, trackbacks - 0, articles - 32