Question: I would like to know what is the difference between these two three pieces of code:

```
underlyingConnectors.values().stream().forEach(connector -> connector.start());

underlyingConnectors.values().forEach(connector -> connector.start());

underlyingConnectors.values().forEach(Connector::start);

```

The second line compiles fine but my Ecplipse IDE complains with "Sonar : Replace this lambda with a method reference".

How do I choose the approriate code to use? Is there a specific use case for each of these?

Answer: 
You can ommit the `.stream()` if you're just doing one operation with every element through `.forEach()`. Calling `.stream()` is redundant.

```
underlyingConnectors.values().stream().forEach(connector -> connector.start());
underlyingConnectors.values().forEach(connector -> connector.start());

```

Line 2 is correct.

If you're just applying one operation to every entry, then just use the method reference, no need to write a lambda. This is basically a shorthand.

```
underlyingConnectors.values().forEach(connector -> connector.start());
underlyingConnectors.values().forEach(Connector::start);

```

Line 2 is correct.
Both lines are correct. It is just a warning of sonar lint. The method reference is a simple form of lambda, in case you are returning just a method.