Menu
Question Index
...

Compare the following Programs?

import java.util.*;
public class CollectionProgram1
{
    public static void main(String args[])
    {
        List<String> list = new ArrayList<String>();
        java.util.ListIterator<String> listIterator = null;
        list.add("Merit ");
        list.add("Campus ");
        list.add("welcomes ");
        list.add("you ");
        list.add("to ");
        list.add("become ");
        list.add("a ");
        list.add("good ");
        list.add("programmer.");

        listIterator = list.listIterator();

        while(listIterator.hasNext())
        {
            System.out.print(listIterator.next());
        }
    }
}

import java.util.*;
public class CollectionProgram2
{
    public static void main(String a[])
    {
        Vector<String> vector = new Vector<String>();
        Enumeration<String> string = null;
        vector.add("Merit ");
        vector.add("Campus ");
        vector.add("welcomes ");
        vector.add("you ");
        vector.add("to ");
        vector.add("become ");
        vector.add("a ");
        vector.add("good ");
        vector.add("programmer.");

        string = vector.elements();

        while(string.hasMoreElements())
        {
            System.out.print(string.nextElement());
        }
    }
}


Both CollectionProgram1 and CollectionProgram2 produce same output.
CollectionProgram1 and CollectionProgram2 produce different output.
CollectionProgram2 will compile and run with out any error,
but CollectionProgram1 will give compilation error.
CollectionProgram1 will compile and run with out any error,
but CollectionProgram2 will give compilation error.
Both CollectionProgram1 and CollectionProgram2 will fail to execute.

Doubts

Problems

Topic: Java Vector

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App