-3

I have a string that I split, it works perfectly until i want to use it : when I use a 'for' to read what a have in my String table I shows exactly what I want, but when I use if(MyStringTable[1] == "a") it isn't true, even though I just saw that MyStringTable[1] was equal to "a". My string table is "static" declared. I'm wondering if there is an invisible character or something that has been created with the split.

  • 1
    try to used string `.equals()` or `.equalsignorecase()` for string equality checking – M D Apr 12 '14 at 17:26
  • NExt time, post your code as well- this was an easy guess, but for a harder problem we're not going to get it without code to debug – Gabe Sechan Apr 12 '14 at 17:45

1 Answers1

3

In terms of Strings, use .equals() in order to check if a String is equal to another. If one of them is a character, cast it previously to a String using .toString() to make it match this approach.

nKn
  • 13,691
  • 9
  • 45
  • 62
  • I said "a" for the exemple, it's actually a string of 5 characters. – user3527316 Apr 12 '14 at 17:31
  • Same goes for that example, if it's an array of characters, simply declare a new `String` via: `String myNewString = new String(characterArray)`. – nKn Apr 12 '14 at 17:32
  • You're welcome. If this helped you (and also regarding to your future questions), you should accept the question that helped you most, you can do this by choosing the 'tick' under the points of the answer you want to accept. This will help other users to know this is the question that helped you and also will help for reputation. – nKn Apr 12 '14 at 17:39