Starts from java 8 to iterate throug list I can use both:
List list = new ArrayList(); 1. list.forEach(...) 2. list.stream().forEach(...) Is it any advantages of using second case? To convert list to stream?
There are no advantages of using the second case, unless you have a parallel stream. There is a disadvantage, namely that Stream.forEach() doesn't guarantee to respect encounter order. A more accurate (but still unnecessary) equivalent would be Stream.forEachOrdered().
forEach also apply to non parallel streams that have ordered source?stream().forEach is strongly discouraged and it might produce wrong results, while the other one would be ok.forEach() and peek(), can operate only via side-effects; these should be used with care.