0

There is a website called CodeFights, and they have a challenge which has caused me a little bit of a problem.

Here is my code:

boolean checkPalindrome(String inputString) {
String[] inputStringArray = inputString.split("");

    String reverseInputString = "";

    for (int x = inputString.length() - 1; x >= 0; x = x - 1) {
        reverseInputString = reverseInputString + inputStringArray[x];
    }

    System.out.println(reverseInputString); // for debugging purposes only 
    System.out.println(inputString); // for debugging purposes only 

    if (reverseInputString == inputString) {
        return true;
    } else {
        return false;
    }
}

The weird stuff:

  • Let's say that inputString equals aba.
  • Then System.out.println(reverseInputString); and System.out.println(inputString); are both going to print out aba, which is just what I want.
  • However, my if statement is going to return false, and I don't have a single clue why it is always happening.

I mean literally, I've tried everything in my knowledge to debug my humble "application", but nada; it doesn't seem to show any sign of working properly. It might very well be that the solution is quite easy, in which case I apologise for even asking this question, however, I've only been learning Java for 3 days, which is not a long period of time.

I am looking forward to reading your ideas and opinion on this matter.

Thank you for your help :)

0 Answers0