scala 跳过Scala可迭代中的前N个元素

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9514663/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 03:56:17  来源:igfitidea点击:

Skip first N elements in scala iterable

scalasequence

提问by em70

I'd like to know if scala includes a way to skip the first N elements of an iterable, so that for instance

我想知道 Scala 是否包含跳过可迭代对象的前 N ​​个元素的方法,例如

(1 to 5).WHATIWANT(3).foreach(println(_))

would print only 4 and 5.

只会打印 4 和 5。

I understand there's slice, but if the length of the sequence can't be obtained in advance, like in my case, that's not gonna do.

我知道有切片,但如果不能提前获得序列的长度,就像在我的情况下一样,那是不行的。

Ideas?

想法?

回答by Eastsun

(1 to 5).drop(3).foreach(println(_))