Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created September 2, 2019 18:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/7ad651ca4172c48a5b77c74cc055828e to your computer and use it in GitHub Desktop.
Save parzibyte/7ad651ca4172c48a5b77c74cc055828e to your computer and use it in GitHub Desktop.
// Voy a buscar únicamente comparando el código
boolean encontrado = false;
for (int x = 0; x < productos.size(); x++) {
Producto p = productos.get(x);
if (p.getCodigo().equals(busqueda.getCodigo())) {
encontrado = true;
break; // Terminar ciclo, pues ya lo encontramos
}
}
// Al terminar el ciclo comprobamos si se movió la variable
if (encontrado) {
System.out.println("El producto existe");
} else {
System.out.println("El producto NO existe");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment