Menu
Topics Index
...
`

Creating ArrayList


If you need explanation Read this topic

If you need Answer Take test on this topic

Creating ArrayList
What will be the output of the following program?
import java.util.*;
public class IamwhatIam {
    public static void main(String[] args) {
        List<String> truth = new ArrayList<String>();
        truth.add("I");
        truth.add(" am ");
        truth.add("what");
        truth.add(" I ");
        String[] truths = truth.toArray(new String[truth.size()]);
        System.out.println(truth);
        List<String> trooth = Arrays.asList(truths);
        System.out.println(trooth);
        trooth.add(truths[1]);
        System.out.println(trooth);
    }
}

A. [I,  am , what,  I ]
[I,  am , what,  I ]
[I,  am , what,  I , I]
B. [I,  am , what,  I ]
[I,  am , what,  I ]
[I,  am , what,  I ,  am ]
C. I am what I 
I am what I 
I am what I  am
D. I am what I 
I am what I 
I am what I I
E. Compilation Error
F. Runtime Error
Topic: java.util.Arrays - Class Arrays In Collection Framework

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

F Run time Error

Posted by Ananth Sathvick    2014-07-08 12:51:30


ans is F it prints [I, am, what, I]
[I, am, what, I]  and exception occurs at trooth.add(truths[1]); line as unsupported conversion

Posted by Bharath Yelchuri    2014-07-08 14:33:25


Congratulations Bharath Yelchuri. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-07-09 04:44:59


© meritcampus 2019

All Rights Reserved.

Open In App