如何检查字符串是否为空且不为空?
public void doStuff(String str)
{
if (str != null && str != "**here I want to check the 'str' is empty or not**")
{
/* handle empty string */
}
/* ... */
}
Run Code Online (Sandbox Code Playgroud) 由于这个问题,
我想StringEscapeUntils在包中使用class org.apache.commons.lang3.
但是当我尝试Apache通过添加行compile 'org.apache.commons:commons-collections4:4.0'到build.grade文件来导入lib时,则无法导入上面的类.
有没有人可以帮助我如何通过gradle导入上面的项目(不是通过下载.jar并将它们放入项目文件夹).
我有一个字符串,我必须用子字符串替换它.例如,"服务"就是这个词.我有一个子串作为"servi".现在,我需要检查"服务"是否有"服务".如果是,那么我需要用"服务"替换它.当我尝试更换时,它会显示为"服务".但预期的输出是"服务"你能帮助我解决这个问题吗?请在下面找到代码.
String stringValue = "Servicing";
if (stringValue != null && stringValue != "") {
i = stringValue.toLowerCase().indexOf("servi", i+1);
if(i>=0){
newData = stringValue .replaceAll("(?i)"+"servi", "<mark>"+"servi"+"</mark>");
System.out.println(newData); // Case sensitive should remain same as String. Not as substring.
i = -1;
}
}
Run Code Online (Sandbox Code Playgroud)