我需要 Groovy 中特定长度的子序列
我有一个像这样的 Groovy 代码来查找 subsequence
:
def number = "248" as List
def number1= number.subsequences()
输出:
[[8], [2, 4, 8], [2, 8], [2], [4, 8], [4], [2, 4]]
现在我想要的是特定长度的子序列。比方说,我只想要长度为 3 的子序列,那么对于我们的示例,我们只需要获取 [2, 4, 8]
作为输出。
如何在常规中做到这一点?
提前致谢。
I have a Groovy code like this to find the subsequence
:
def number = "248" as List
def number1= number.subsequences()
Which outputs :
[[8], [2, 4, 8], [2, 8], [2], [4, 8], [4], [2, 4]]
Now what I want is a subsequence of a particular length. Lets say for example I want only the subsequence of length 3, then for our example we need to get only [2, 4, 8]
as output.
How to do this in groovy?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该能够使用 findAll:
You should be able to use findAll: