Menu
Topics Index
...
`

List and Checked List1166


If you need explanation Read this topic

If you need Answer Take test on this topic

List and Checked List1166
import java.util.*;

public class NewJavaClass
{
    public static void main(String args[])
    {
        List<String> list1 = new ArrayList<String>();
        Collections.addAll(list1, "Kiran", "Kumar", "Praveen");
        list1.add("Dharma");
        list1.add("Ashok");
        list1.add("Naveen");
        
        List<String> list2 = new ArrayList<String>();
        Collections.addAll(list2, "Shiva", "Mahesh", "Srinath");
        list2.add("Naryana");
        list2.add("kiran");
        System.out.println(Collections.disjoint(list1, list2));
        
        list2.add("Kumar");
        System.out.println(Collections.disjoint(list1, list2));
    }
}

A. true
true
B. false
false
C. true
false
D. false
true
E. Compilation Error or Runtime Error
Topic: Java Collection Algorithms

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.

Ans is C here we have the List Concept which will store the different type of Objects, here we create the List which can store the String objects and next we are calling the addAll() method by passing the list1 and some string objects than list will store the passed objects and next we are adding some elements to the list using the add() next we create another list with the String and adding some objects to it next we are calling disjoint() by passing the both list1 and list2 this method will return true if the lists doesnot contain any commaon objects for now both dont have any common elements so it will return true, next we are adding() to the list2 and calling the disjoint() so now it wil return falase bcz kumar is present in both the lists

Posted by Uday Kumar    2015-03-11 01:51:40


This dose is now closed and the winners are Uday Kumar,  for 'First Correct Comment', Uday Kumar,  for 'Best Comment' and Uday Kumar for the 'Popular Comment'. The 'lucky liker' is Maheshwari Natarajan. Please login into Merit Campus using facebook, to claim your recharge. Go to http://java.meritcampus.com/earnings to raise the recharge.

Posted by Merit Campus    2015-03-12 01:49:29


© meritcampus 2019

All Rights Reserved.

Open In App