2
I’m not getting a simple comparison I’m making, but it’s not performing like I think it should.
Situation
I request that the user type the person’s name, and capture with String nome = scan.next();
And send to this function :
// FIND PESSOA
private boolean findPessoaInList(String nome){
Boolean _return = false;
for(Pessoa p : this.pessoas){
if(p.getNome() == nome){
_return = true;
// return true;
}
}
return _return;
}
to check whether the person is already registered.
Yet never falls inside the if
even if the name already exists in the list.
Code getNome
in Pessoa
public String getNome() {
return nome;
}
If anyone could explain to me what’s going on, I’d appreciate it.
You have considered using the equals method instead of the operator ==?
– Filipe Miranda
I didn’t even remember this method sorry, I always programmed in PHP and javascript in which comparison is made with
==
or===
– Guilherme Lautert