Programming Concepts using Java, Quiz 2
Consider the Java code given below.
import java.util.*;
public class SetIteratorTest { public static void main(String[] args) { var set1 = new HashSet<String>(); set1.add("Cherry"); set1.add("Banana"); set1.add("Apple"); set1.add("Date");
var set2 = new TreeSet<String>(set1); Iterator<String> it1 = set1.iterator(); Iterator<String> it2 = set2.iterator();
while (it1.hasNext()) { System.out.println(it1.next()); }
while (it2.hasNext()) { System.out.println(it2.next()); } }}Choose the correct option.
Consider the Java code given below. import java.util.*; public class SetIteratorTest { public static void main(String[] args) { var set1 = new HashSet<String>(); set1.add("Cherry"); set1.add("Banana"); set1.add("Apple"); set1.add("Date"); var set2 = new TreeSet<String>(set1); Iterator<String> it1 = set1.iterator(); Iterator<String> it2 = set2.iterator(); while (it1.hasNext()) { System.out.println(it1.next()); } while (it2.hasNext()) { System.out.println(it2.next()); } } } Choose the correct option. Consider the Java code given below. interface Language{ void display(); } class French implements Language{ public void display() { System.out.println("French Language"); } } class English implements Language{ public void display() { System.out.println("English Language"); } } class LanguageList{ private Object[] LArr = {new French(), new English()}; public void getInfo(){ for(int i = 0; i < LArr.length; i++){ //LINE 1 } } } public class Test{ public static void main(String[] args) { LanguageList aList = new LanguageList(); aList.getInfo(); } } Identify the appropriate option to fill in place of LINE 1 such that the output is\ French Language\ English Language Consider the following Java code. import java.util.stream.*; public class Test { public static void main(String[] args) { String[] colors = {"red", "green", "blue", "yellow"}; Stream.of(colors).map((color) -> color.length()) .filter((length) -> length % 2 == 0) .forEach((x) -> System.out.println(x)); } } What will the output be?