I have a problem when it comes to finding a book object through an attribute (isbn) in a collection, I have the attribute to compare but I can't access the same attribute of the objects in my collection, I don't add more implementation to simplify the doubt as much as possible, it throws me this error ( The type of the expression must be an array type but it resolved to ArrayList of books ) please, how could I do the type conversion to have the correct if() expression?:
ArrayList<Libro> coleccion1 = new ArrayList<Libro>();
Libro libro = new Libro();
for (int i = 1; i <= 5; i++) {
libro.crearLibro();
coleccion1.add(libro);
}
socketAlCliente = socketServidor.accept();
System.out.println("Petición número: "+ peticiones);
entrada = new InputStreamReader(socketAlCliente.getInputStream());
BufferedReader bf = new BufferedReader(entrada);
String librorecibido = bf.readLine();
int isbnrecibido = Integer.parseInt(librorecibido);
for (int i = 0; i < coleccion1.size(); i++) {
if(isbnrecibido == coleccion1[i].getisbn) {
}
It's actually
coleccion1
aArrayList
so to access its elements use the methodget()
and the element's index, assuming your objectLibro
has a "getter" calledgetisbn()
, you can get the value like this:This would be applying it to your code: