Menu
Topics Index
...
`

Number of copies of A


If you need explanation Read this topic

If you need Answer Take test on this topic

Number of copies of A
What will be the output of the following program?
import java.util.*;

public class ListContains
{
    public static void main(String[] args)
    {
        List list = Collections.nCopies(6, "A");
        System.out.print("List contains: ");
        Iterator itr = list.iterator();
        while (itr.hasNext())
            System.out.print(itr.next() + " ");
    }
}

A. List contains: A A A A A A
B. List contains: A A A A A A A
C. List contains: 6 A
D. Compilation Error because there is no such method as nCopies
E. Compilation Error or Runtime Error for some other reason
Topic: Java nCopies Collections - Collections.nCopies() Method

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.

answer is A..becoz  in the method nCopies(int n, T o)

n-- The number of elements in the returned list.

o-- The element to appear repeatedly in the returned list.
as the n value is 6..'A' gets repeated for 6 times..thus the answer is A...

Posted by Sneha Rapool    2014-06-18 09:01:37


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

Posted by Merit Campus    2014-06-19 06:34:20


© meritcampus 2019

All Rights Reserved.

Open In App