this is my first topic, i'm pt-br, so beforehand i will apologize for my english.
Here's my question, i have this code, i type the id to look in the ArrayList if there are equals, if positive, it brings to the screen the registered item, if negative, it goes to the else.
But in this code, it's going to the else even when there are a registered item. It shows the registered item and then the else block code is executed.
I don't know what's going on, for me it's correct.
//abre a opção para o usuário digitar o id para a busca
int opcao = Integer.parseInt(JOptionPane.showInputDialog("Digite o ID para a busca"));
//'for' para percorrer o vetor
for (Produto objProduto : vetorProdutos2) {
//if para verificar se o ID digitado para busca contém no vetor
if (objProduto.getId() == opcao) {
JOptionPane.showMessageDialog(null,
"\nID: " + objProduto.getId() + "\nDescrição: " + objProduto.getDescricao()
+ "\nEstoque: " + objProduto.getEstoque() + "\nPreço: "
+ objProduto.getPreço() + "\nStatus: " + objProduto.getStatus());
} else if (objProduto.getId() != opcao) {
JOptionPane.showMessageDialog(null, "Produto não encontrado");
}
}