Write a command line program that will print out the lyrics to 99 Bottles. Bottles of what? Make a variable for what is in the bottle (so it can be easily changed) and start it out as “beer” or another beverage of your choice, if you would like. Also, extract a variable to represent the initial number of bottles. Output should look as follows:
Breaking it down
Since there isn't a way to peek at the next value in a stream, we will need to seperate the 99 bottles of beer lyrics into to lists concatinating inital seed values and beverage variable. Next, we can iterate over a series of Integer using java8 range. The catch is we want to perform the operation in reverse order such as [99..1] and in order to do this we will need to reverse the stream. Converting the IntStream to an iterator we can loop over the elements checking if we have reached the end.
Diving into the while loop, we can use the map function to replace any of the numbers. To learn more about the map function visit java 8 map tutorial. Next we can println java 8 stream using the forEach and referencing the static method System.out::println.