Groovy 从两个列表构建一个列表

Mat*_*rps 0 groovy

我有两个这种形式的数组列表:

\n
def AllowedExtensions = [ '.mxf', '.mov', '.mp4']\ndef myPaths = [C:\\Temp\\Media\\Media.c2v, C:\\Temp\\Media\\Media.V2C, C:\\Temp\\Media\\toto\\test\\\xe5\xb7\xa8\xe5\xa1\x94\xe3\x81\xae\xe7\xb5\x82\xe3\x82\x8f\xe3\x82\x8a.mp4, C:\\Temp\\Media\\toto\\toto.mxf]\n
Run Code Online (Sandbox Code Playgroud)\n

我正在尝试构建一个新列表,mySelectedPathmyPaths当它与 \n中的扩展名之一匹配时,我AllowedExtensions正在寻找一种常规方法来执行此操作,但无法使其正常工作。

\n
AllowedExtensions.each { mySelectedPath =  myPaths.findAll { it }}\n
Run Code Online (Sandbox Code Playgroud)\n

这是我的预期结果:

\n
[C:\\Temp\\MediaNavigator\\toto\\toto.mxf, C:\\Temp\\MediaNavigator\\toto\\test\\\xe5\xb7\xa8\xe5\xa1\x94\xe3\x81\xae\xe7\xb5\x82\xe3\x82\x8f\xe3\x82\x8a.mp4]\n
Run Code Online (Sandbox Code Playgroud)\n

感谢您的任何意见!

\n

tim*_*tes 5

另一种解决方案是使用findResults

allowedExtensions.findResults { ext -> myPaths.find { it.endsWith ext } }
Run Code Online (Sandbox Code Playgroud)

如果您希望每个扩展程序有多个结果,请尝试:

allowedExtensions.findResults { ext -> myPaths.findAll { it.endsWith ext } }.flatten()
Run Code Online (Sandbox Code Playgroud)