Chapter Summary
If a method definition includes an invocation of the method itself, that invocation is known as a recursive call. Recursive calls are legal in Java and can sometimes make a method definition clearer.
Whenever an algorithm has one subtask that is a smaller version of the entire algorithm’s task, you can realize the algorithm as a Java recursive method.
To avoid infinite recursion, a recursive method definition should contain two kinds of cases: one or more cases that include a recursive call and one or more base (stopping) cases that do not involve any recursive calls.
Two good examples of recursive algorithms are the binary search algorithm and the merge sort algorithm.
A lambda function is a nameless function that allows you ...
Get Java: An Introduction to Problem Solving and Programming, 8th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.