Share on Google+Share on Google+

SCJP Module-9 Question-27

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)

 

Advertisements

Posted on: July 19, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial 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.