如果字符串包含语句,则使用Java OR运算符 [英] Java OR operator in if string contains statement

查看:77
本文介绍了如果字符串包含语句,则使用Java OR运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码。

for (String str5 : verticesposition2) {
    if(!str5.contains(("Vertex")||("Name")||("Transmittance")) {
        System.out.println(str5); 
    }                           
}

如上所示,如果字符串不包含顶点,名称或透射率,我希望将其打印出来。收到一个编译错误,指出||运算符未定义参数类型。我是编程新手,所以我不确定这意味着什么,有人可以在正确的方向上指出正确的代码吗?

As you can see above if the string does NOT contain Vertex, Name or Transmittance I want it to print out. However Im getting a compilation error saying that the || operator is undefined for the argument types. I'm relatively new to programming so Im not sure what this means could someone kindly point in the right direction on how to fix my code?

推荐答案

||运算符适用于单个布尔项,而不是提供许多不同的参数。

The || operator works on individual boolean terms, not to provide a bunch of different arguments.

if((!str5.contains("Vertex")||!str5.contains("Name")||!str5.contains("Transmittance")){

这篇关于如果字符串包含语句,则使用Java OR运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆