What does this code mean and what do you want to do with this expression? [closed]

-3

// server refers to an attribute of type Server that is a class

server.clients

.stream()
.filter(h -> (destinatario.equals(h.getIdentificador())))
.forEach((h) -> h.enviarMensaje(lista));
    
asked by fvf 12.03.2017 в 12:43
source

1 answer

2

Your code uses Streams is a new integrated functionality from Java 8 and means the following:

.stream()  //convierte una Lista (java.util.List) a una instancia stream
.filter(h -> (destinatario.equals(h.getIdentificador()))) //solo deja en el stream a los elementos que retornen true en el siguiente fragmento (destinatario.equals(h.getIdentificador())
.forEach((h) -> h.enviarMensaje(lista)); //el metodo forEach() recibe un Consumer el cual debe ser una instruccion con resultado void y la ejecuta con todos los elementos restantes del stream

I hope it serves you, Regards.

    
answered by 12.03.2017 в 14:18