-1

My question is why don't enter into if when acc.getUsername equals "stringExample"? When I print acc.getUsername() this line ealier it shows its equals but dont go into if, why?

@RequestMapping(value = "/login", method = RequestMethod.POST)
    public ModelAndView checker(@ModelAttribute(value="acc") Account acc) {

        System.out.println(acc.getUsername());
        if(acc.getUsername() == "stringExample"){
            System.out.println("aaa");
        }

        ModelAndView model2 = new ModelAndView("index.jsp");
        return model2;
    }
Xstian
  • 8,184
  • 10
  • 42
  • 72
MSB MSB
  • 13
  • 1
  • 5

1 Answers1

-1

In Java when you want to compare Strings contents you should compare them using equals() method:

acc.getUsername().equals("stringExample")
Keammoort
  • 3,075
  • 15
  • 20