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 }
精彩评论