I have the following code which is attached to my window. Whenever the user presses a keyboard, that character is saved to a 8 character long array in a StringBuilder class.
When the user types "somecode" then the something() method should be called.
static StringBuilder    s   = new StringBuilder("aaaaaaaa");
public static void listen() {
     Main.sc.setOnKeyPressed(new EventHandler<KeyEvent>() {
            @Override
            public void handle(KeyEvent event) {
                {
                    for(int i=0; i<7; i++) {
                        s.setCharAt(i, s.charAt(i+1)); // the characters move 1 position backwards
                    }    
                    char c = event.getText().charAt(0);
                    s.setCharAt(7, c);
                    System.out.println(s.toString());
                    if(s.toString()=="somecode") {
                        System.out.println("--------------------------");
                        something();
                    }
                }
            }
        });
}
My output is:
aaaaaaas
aaaaaaso
aaaaasom
aaaasome
aaasomec
aasomeco
asomecod
somecode
However the something() method is never called, nor is the "-----------------" displayed.
EDIT: This has been tagged as duplicate, however .equals() is not working either
if(s.equals("somecode")) {
                        System.out.println("--------------------------");
                        something();
                         }
