Share on Google+Share on Google+

SCJP Module-9 Question-11

Advertisement
The sample program given below will test your understanding of inserting data into the object of the ArrayList class and printing them using for loop.

Given below the sample code :

public class Check{
public static void main(String... args) {
ArrayList<Integer> alist = new ArrayList<Integer>();
alist.add(3);
alist.add(12);
alist.add(21);
alist.add(30);
for(int a : alist)
System.out.println(a);
}
}

What will be the output of the above code ?

1. compile error

2. 3 12 21 30

3. 0 0 0 0

4. 30 21 12 3

Answer

(2)

Advertisements

Posted on: July 17, 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.