Getting started
- The original Java review plus
- A half-way house of Java code
Action Ε: Getting more generic
Make you class into a generic Lollypop<T>
with constructor arguments of type List<T>.
For now, you should just remove the constructor arguments for the integer array. We will get back to that one later.
Action Ζ: Testing generic
Test out your program by adding a second type, I suggest
List<String>. You might find the following
useful for your two arrays:
String[] startNames =
{"zero", "one", "two", "three", "four",
"five", "six", "seven", "eight", "nine" } ;
String[] loopNames =
{"ten", "eleven", "twelve", "thirteen", "fourteen",
"fifteen", "sixteen", "seventeen", "eightteen", "nineteen" } ;
Be sure to use both Integer and String
in your program.
Action Η: Converting array to List
Get on the net and
look up information about converting an array into an
List.
There are some wild answers out there.
See if you can get any to work.
Be sure to save your old program before trying out these newfangled JDK 8+ features.
Action ?:
- Look at page 162 in the textbook for a use of a functional interface andλ expression in Java. We did something like this in this week’s CSCI 235 lab.
- Page 460 of the textbook shows a use of the Java functional interface in JavaFX. When Joe Daugherty taught CSCI 202, these interfaces were used.
Next week we will look at some new things in JDK 8:
Stream and Collectors.
Look at the whole tutorial on Nested Classes and pay attention to the section on Lambda Expressions. Also, read the Tutorial on Collections with a focus on Aggregate Operations. For more information look at the documentation for java.util.stream.