• It can be used in the methods that need functions as parameter.

E.X;

numbers.sort((a,b) -> a.compareTo(b));

forEach

  • Usually combined with Lambda.
  • Iterating with forEach → Set is read-only during iteration (cannot modify). So It’s advised to use it for things that wouldn’t modify the set.

java