This question already has an answer here:
这个问题在这里已有答案:
- How do I compare strings in Java? 23 answers
如何比较Java中的字符串? 23个答案
String TypedMaxNumber = MaxValue.getText();
if(TypedMaxNumber == "100")
System.out.println(TypedMaxNumber+" = 100");
I think it is a silly problem, but when I am running to run this program and I type 100 in the text Field it is not going inside the loop. What could be the reason.
我认为这是一个愚蠢的问题,但是当我运行这个程序并在文本字段中输入100时,它不会进入循环。可能是什么原因。
1 个解决方案
#1
1
I am running to run this program and I type 100 in the text Field it is not going inside the loop.
我正在运行这个程序,我在文本字段中输入100,它不会进入循环内部。
Its
if(TypedMaxNumber.equals("100"))
Since TypedMaxNumber
is of type String
. equals()
check for value equality
由于TypedMaxNumber的类型为String。 equals()检查值的相等性
#1
1
I am running to run this program and I type 100 in the text Field it is not going inside the loop.
我正在运行这个程序,我在文本字段中输入100,它不会进入循环内部。
Its
if(TypedMaxNumber.equals("100"))
Since TypedMaxNumber
is of type String
. equals()
check for value equality
由于TypedMaxNumber的类型为String。 equals()检查值的相等性