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

 
 

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

 

Advertisement

Related Tags for SCJP Module-9 Question-27:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: July 19, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com