Menu
Question Index
...

What will be the output of the following program?

import java.util.*;
public class SingletonCollectionsTest {
    public static void main(String[] args) {
        Set<String> meritSet = Collections.singleton("Merit");
        List<String> meritList = Collections.singletonList("Merit");
        p(meritSet.contains(meritList), 'J');
        p(meritList.contains(meritSet), 'A');
        p(meritSet.containsAll(meritList), 'V');
        p(meritList.containsAll(meritSet), 'A');
        meritSet.add("Campus");
        meritList.addAll(meritSet);
        System.out.print(Collections.indexOfSubList(meritList, new ArrayList<String>(meritSet)));
    }
    private static void p(boolean condition, char c) {
        if (condition) {
            System.out.print(c);
        }
    }
}


JAVA0
VA1
JA1
Compilation Error
Runtime Error

Doubts

Problems

Topic: Java Singleton

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App