Question: IN JAVA. please post as copyable text code, Not an image. 1. Collections Programming: Write a method called retainEvenLength that takes a Set of strings
IN JAVA. please post as copyable text code, Not an image.
1. Collections Programming: Write a method called retainEvenLength that takes a Set of strings as a parameter and that retains only the strings of even length from the set, removing all other strings. For example, if a Set called s stores the following values:
[I, Sam, am, and, do, eggs, green, ham, like, not, them] and the following call is made:
retainEvenLength(s); then s should store the following values after the call:
[am, do, eggs, like, them]
Turn in just the code for this method and your console output. I will test your code with the examples values above.
2. Collections Programming: Given this Test Program:
public class EC2 { public static void main(String[] args) {
}
String[] words = {"to", "be", "or", "not", "to", "be", "Hamlet"}; ArrayList
al.add(w);
} System.out.println(al);swapPairs(al); System.out.println(al);
public static void swapPairs(ArrayList
} }
Fill in the swapPairs method so that pairs of words are swapped in place in the ArrayList. Your program should generate this output from the input in main:
[be, to, not, or, be, to, Hamlet]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
