SCJP Module-9 Question-19


 

SCJP Module-9 Question-19

The sample program given below will test your understanding about the List and Collection interface of Collection framework.

The sample program given below will test your understanding about the List and Collection interface of Collection framework.

Given below the sample code :

import java.util.*;
public class z {
public static void Find(List<String> list) {
list.clear();
list.add("ba");
list.add("aa");
list.add("ca");
list.add("ca");
System.out.println(Collections.binarySearch(list, "ca"));
System.out.println(list);
}
public static void main(String[] args) {
List<String> list = new ArrayList<String>();
Find(list);
}}


What will be the output of the above code ?

1. Undefined : no output

2. 2

3. [ ba, aa , ca, ca ]

4. 2  [ba, aa , ca, ca]

Answer

(4)


Ads