Java Reference
In-Depth Information
Java 8 Iterable.foreach
Own Functional Interfaces
)
that you don't have to write. Thus, without changing the
Ar-
rayIterator
, after moving to Java 8 we can use the newest-style loop,
Iterat-
or.foreach(Consumer)
, with a lambda expression (see
Chapter 9
) to print each element
(see
Figure 7-2
).
Stack
Problem
You need to process data in “last-in, first-out” (LIFO) or “most recently added” order.
Solution
Write your own code for creating a stack; it's easy. Or, use a
java.util.Stack
.
Discussion
You need to put things into a holding area quickly and retrieve them in last-in, first-out order.
This is a common data structuring operation and is often used to reverse the order of objects.
The basic operations of any stack are
push()
(add to stack),
pop()
(remove from stack), and