[英]error in replaceAll() method
i have error in String st=str.replaceAll(" ","");
我在
String st=str.replaceAll(" ","");
有错误String st=str.replaceAll(" ","");
But include the import java.lang.String.*;
但是包括
import java.lang.String.*;
After adding this line again same error repeated.. So please anyone help me to solve the error.. 再次添加此行后,重复相同的错误。.因此,请任何人帮助我解决错误..
String st=str.replaceAll(" ","");
We can't really tell what's wrong without you telling us the error message or giving us more code. 没有您告诉我们错误消息或提供更多代码,我们就无法真正判断出问题所在。 Your snippet is missing a semi-colon, and relies on
str
being a definitely-assigned variable of type String, but that's all. 您的代码段缺少分号,并且依赖于
str
是String类型的绝对分配变量,仅此而已。
Sample code that works: 有效的示例代码:
public class Test {
public static void main(String args[]) {
String str = "hello world";
String st = str.replaceAll(" ", "");
System.out.println(st); // helloworld
}
}
Now you just need to find the difference between your code and my code... 现在您只需要找到您的代码和我的代码之间的区别...
If I understood you properly, you used the line twice, like this: 如果我对您的理解正确,那么您会使用该行两次,如下所示:
// in scope of some method:
String st=str.replaceAll(" ","");
//....
String st=str.replaceAll(" ","");
This is not legal, because you declared a variable with the same name in the same scope twice, instead, it should be: 这是不合法的,因为您在相同的作用域中两次声明了具有相同名称的变量,而应该是:
// in scope of some method:
String st=str.replaceAll(" ","");
//....
st=str.replaceAll(" ","");
or: 要么:
// in scope of some method:
String st=str.replaceAll(" ","");
//....
String st1=str.replaceAll(" ","");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.