I saw the following code in the project (Spring):
manRepository.findAll().forEach(mans::add); What kind of interesting forEach?
I only know this:
for(int i: list(массив или коллекция)){ //тело цикла } This is forEach for collections, which takes lambda, and lambda itself can be replaced by a reference to the method
List<Integer> ints = new ArrayList(); ints.add(1); ints.add(2); List<Integer> copy = new ArrayList(); ints.forEach(copy::add); ints.forEach(oneIntFromInts -> copy.add(oneIntFromInts)); //эквивалент строке выше copy.forEach(oneIntFromCopy -> System.out.println(oneIntFromCopy)); Source: https://ru.stackoverflow.com/questions/939432/
All Articles
Stream API- gil9red