变量中的Java if字符串



对java来说非常陌生,但我似乎找不到如何在java中做到这一点。。

var1 = "testing101"
if("101" in testing) balala

在java中我该怎么做?

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;


public class Main {
    public static void buttonPressed(String[] args) {
        WebDriver driver = new ChromeDriver();
        driver.get("http://www.csgodouble.com/index.php");
        WebElement rollingTimer = driver.findElement(By.xpath("//*[@id="banner"]"));
        if(rollingTimer :: "Rolling in 41")
    }
}

我以为是这样做的。。

如果您试图查看字符串是否包含子字符串:

String var1 = "testing101"
if(var1.contains("101"))

我认为您可能想要使用String类的contains方法。

对于Java中的字符串,查看一个字符串是否包含在另一个字符串中do:

String str1 = "testing 1";
if(str1.contains("testing"))
{
     //Add your code here
 }

同样,您可以比较字符串进行相等性检查,

    if("Rolling in 41".equals(rollingTimer )){ // compare with case-sensitive
    }
    // OR this way also
if("Rolling in 41".equalsIgnoreCase(rollingTimer )){ // compare without case-sensitive
    }

最新更新