
Consider this method:
public static String largest(String[] values, Comparator<String> comp)
{
String result = null;
for (int i = 0; i < values.length; i++)
if (i == 0 || comp.compare(result, values[i]) < 0)
result = values[i];
return result;
}
What is the result of this call?
String[] words = { "Mary", "had", "a", "little", "zebra" };
String largestWord = largest(words, (s, t) -> Math.max(s.length(), t.length()));
"Mary""little""zebra"Consider this method:
public static String largest(String[] values, Comparator<String> comp)
{
String result = values[0];
for (int i = 1; i < values.length - 1; i++)
if (comp.compare(result, values[i]) < 0)
result = values[i];
return result;
}
What is the result of
String result = largest(new String[] { "Mary" }, null);
NullPointerExceptionArrayIndexOutOfBoundsException"Mary"
Collection<T> interface has a method removeIf that accepts a Predicate<T>, a functional interface for a function T → boolean. All elements for which the function is true are removed.
~/oodp3code/ch04/action1/ActionTester.java file into your lab9 directory.JButton.setEnabled.Hello 1, Goodbye 1, Hello 2, and so on, incrementing with each button click. 