开发者

I need Subsequence of a particular length, in Groovy

I have a Groovy code like this to find the subsequence :

def number = "248" as List
def number1= num开发者_StackOverflow社区ber.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.


You should be able to use findAll:

    number.subsequences().findAll { it.size() == 3 }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜