The ==
operator compares the object references, not the value of the String
s.
To compare the values of String
s, use the String.equals
method:
"231".equals(parts[0]);
This is true with any other object in Java -- when comparing values, always use the equals
method rather than using the ==
operator.
The equals
method is part of Object
, and should be overridden by classes which will be compared in one way or another.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…