Created
September 2, 2019 17:33
-
-
Save parzibyte/27d96366962049e561a13de1bce46a33 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Buscar elemento en ArrayList de Java | |
https://parzibyte.me/blog | |
*/ | |
import java.util.ArrayList; | |
class Main { | |
public static void main(String[] args) { | |
ArrayList<String> canciones = new ArrayList<>(); | |
// Le agregamos datos | |
canciones.add("Beds are burning"); | |
canciones.add("It's only rock 'n' Roll (But I like it)"); | |
canciones.add("Ashes to ashes"); | |
String busqueda = "Ashes to ashes"; | |
int indice = canciones.indexOf(busqueda); | |
if (indice != -1) { | |
System.out.println("La búsqueda está en el índice " + indice); | |
} else { | |
System.out.println("El elemento no existe"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment