Home Tutorial Java Scjp Part9 SCJP Module-9 Question-27

 
 

SCJP Module-9 Question-27
Posted on: July 19, 2010 at 12:00 AM
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)

 

Related Tags for SCJP Module-9 Question-27:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.