groovy - 如何查找 groovy args 是否包含特定字符串

标签 groovy

println args

println args.size()

println args.each{arg-> println arg}

println args.class

if (args.contains("Hello"))
    println "Found Hello"

运行时出现以下错误:

[hello, somethingelse]
2
hello
somethingelse
[hello, somethingelse]
class [Ljava.lang.String;
Caught: groovy.lang.MissingMethodException: No signature of method: [Ljava.lang.
String;.contains() is applicable for argument types: (java.lang.String) values:
[Hello]

为什么我不能执行contains

最佳答案

因为argsString[]但不是List<String>

您可以使用

if (args.grep('Hello'))
    println "Found Hello"

关于groovy - 如何查找 groovy args 是否包含特定字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2434013/

相关文章:

groovy - 如何使用 groovy 创建和配置新的 Jenkins 作业?

groovy - 为什么 Groovy 闭包声明一个最大值,而不是常量数量的参数

android - 如何在 Live Template 中自动导入项目的 R?

groovy "with" block 使用情况查询

jenkins - 如何访问 Jenkins Pipeline 项目中的 Junit 测试计数

groovy - 无法使用具有 createCriteria() 语句的函数执行单元测试

groovy - 在工作流脚本中使用 Jenkins Java API

jenkins - Jenkins工作流程结帐访问BRANCH_NAME和GIT_COMMIT

xml - 如何在使用 XmlSlurper 解析 xml 时读取带连字符的属性名称(例如 model_name)

grails - 发布 Grails 插件