java - Why can't I properly parse an Array of Strings? -
I'm having trouble with parsing strings; I can not know why my strings are not equal to Array's values what they want! It may look strange, so it's a simplified version of code (the application is too big, so I made a small program to explain my point)
test for the public class {public Static zero} main (string [] algs) {string src = "beep zap denrup flop"; String Delimits = "[] +"; String [] token = src.split (delims); If (token [0] == "beep") {System.out.println ("You said beep!"); } Else {for (int i = 0; i & lt; tokens.length; i ++) {System.err.println ("'" + token [i] +' '' ')}}}} My output is
'beep' 'zap' 'darap' 'flop' I have a fact I know the token [0] is a beep, but Java does not notice. Is there something I'm doing wrong?
Use == operator with strings in Java when using objects such as strings If done, then == operate In comparison, == will return only true for both the terms if both references refer to the same exact object, compared to context for equality If you have two separate string objects, then == returns false , even if the content is the same
Same, this method will compare the String character-by-character basis of material objects.
Comments
Post a Comment