SCJP Module-9 Question-27


 

SCJP Module-9 Question-27

The Sample example given below will tests your knowledge about the List and ArrayList in Java, and also examine your understanding that how to get the first element from the list.

The Sample example given below will tests your knowledge about the List and ArrayList in Java, and also examine your understanding that how to get the first element from the list.

Given below the sample code :

1public static void addition(List list) {
2list.add("0021");
3}
4public static void main(String[] args) {
5List<Integer> myList = new ArrayList<Integer>();
6addition(myList);
7System.out.println(myList.get(1));
8 }

How can we correct the above code ?

1. By changing the value of the method "myList.get(1)" to "myList.get(0)".

2. No need of the correction.

3. By changing the value of the method "myList.get(1)" to "myList.get(-1)".

Answer

(1)

 

Ads