0

I am using Amazon Web Services s3, and am using it to, - open a connection (working fine) - open an input stream from a text file that has usernames and passwords listed username,password username,password ... all that works fine, I run into issues when trying to check if a username matches with a password.

Take a look,

            while (INFINITE == 1) {
            System.out.println("ran");
            if (tryToLogin == true) {
                System.out.println("ran2");
                tryToLogin = false;
             BufferedReader br = new BufferedReader(new InputStreamReader(object.getObjectContent()));
             String lineValue = null;
             while((lineValue = br.readLine()) != null && loggedInAs == null){
                 String splitResult[] = lineValue.split(",");
               if ("saucymeatman" ==  splitResult[0] && "mufasa" == splitResult[1]) {
                loggedInAs = splitResult[0];
                System.out.println("logged in");
             //ui.usernameLogin.getText()
               }
               else {
                    System.out.println("SPLIT 0 : " + splitResult[0]);
                    System.out.println("SPLIT 1 : " + splitResult[1]);
               }
             }
             }
        }

Even though "saucymeatman" == splitResult[0] && "mufasa" == splitResult[1] It does not print "Logged in" or set loggedInAs to anything. I am sure that splitResult[0] equals "saucymeatman" because it prints "SPLIT 0 : saucymeatman".

Thanks in advance.

  • Do not use `==` to compare `String` values; use the `equals` method of the `String` class. – rgettman Jul 15 '13 at 17:23
  • Works great! Can I give you some kind of reward like a "Thumbs up" or "+1" or whatever this site has for helping? – user1952381 Jul 15 '13 at 17:37
  • If you'd like. But normally this kind of question gets marked as a duplicate of [this question](http://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java). – rgettman Jul 15 '13 at 17:46

1 Answers1

0

Do not use == to compare String values; use the equals method of the String class. The == operator compares objects references to determine if they refer to the same object; it doesn't compare string contents.

rgettman
  • 176,041
  • 30
  • 275
  • 357