0

Java Basics

Description: Question Based on Collections in Java
Number of Questions: 15
Created by:
Tags: Question Based on Collections in Java Java Basics
Attempted 0/15 Correct 0 Score 0

Which of following methods is present in the Collection interface in Java?

  1. hashCode()

  2. hashNext()

  3. Next()

  4. AllRetain()

  5. ensureCapacity()


Correct Option: A
Explanation:

This is the correct answer.

How many constructors are there for LinkedHashSet?

  1. 6

  2. 5

  3. 4

  4. 3

  5. 2


Correct Option: C
Explanation:

This is the correct answer.

Which of the following is not a subclass of RuntimeException?

  1. IllegalArgumentException

  2. NullPointerException

  3. IOException

  4. IndexOutOfBoundException

  5. ArithmeticException


Correct Option: C
Explanation:

IOException is not a subclass of RuntimeException class.

What are the default values for initial capacity and load factor for HashSet?

  1. Initial capacity : 12 Load factor : 0.75

  2. Initial capacity : 14 Load factor : 0.75

  3. Initial capacity : 16 Load factor : 0.75

  4. Initial capacity : 16 Load factor : 0.65

  5. Initial capacity : 12 Load factor : 0.65


Correct Option: C
Explanation:

This is the correct answer. 

Which of the following methods is present in List interface?

  1. subList(int startindex, int endindex)

  2. previousIndex()

  3. nextIndex()

  4. hasPrevious()

  5. hasMiddle()


Correct Option: A
Explanation:

This is the correct answer.

Which of the following methods is present in the vector class in Java?

  1. trimToSize()

  2. setElement(index,Element)

  3. Seach()

  4. Empty()

  5. Remove()


Correct Option: A
Explanation:

This is the correct answer.

Which of the following statements is true for methods in queue in Java Collections?

  1. Element() method retrieves and removes the head of the queue and returns Null if the queue is empty.

  2. Element() method retrieves, but doesn’t remove the head of the queue and returns Null if the queue is empty.

  3. Element() method retrieves and removes the head of the queue and throws exception if the queue is empty.

  4. Element() method retrieves, but doesn’t remove the head of the queue and throws exception if the queue is empty.

  5. Element() method removes the head of the queue and throws exception if the queue is empty.


Correct Option: D
Explanation:

This is the correct answer.

Which of the following statements is correct for the methods in queue in Java Collections?

  1. Poll() method retrieves and removes the head of the queue or returns Null if the queue is empty.

  2. Remove() method retrieves and removes the head of the queue or returns Null if the queue is empty.

  3. Poll() method retrieves and removes the head of the queue or throws an exception if the queue is empty.

  4. Remove() method retrieves and removes the head of the queue, but doesn’t return anything if the queue is empty.

  5. Poll() method retrieves the head of the queue or returns Null if the queue is empty.


Correct Option: A
Explanation:

This is the correct choice.

Which of the following statements is correct for methods in the queue?

  1. Peek() method retrieves and removes the head of the queue and returns Null if the queue is empty.

  2. Peek() method retrieves and removes the head of the queue and returns nothing if the queue is empty.

  3. Peek() method retrieves, but doesn’t remove the head of the queue and returns Null if the queue is empty.

  4. Peek() method retrieves and removes the head of the queue and throws an exception if the queue is empty.

  5. Peek() method retrieves, but doesn’t remove the head of the queue and throws an exception if the queue is empty.


Correct Option: C
Explanation:

This is the correct answer.

How many constructors are there of TreeSet class?

  1. 6

  2. 5

  3. 4

  4. 3

  5. 2


Correct Option: C
Explanation:

This is the correct answer.

How many constructors are there of HashSet?

  1. 6

  2. 5

  3. 4

  4. 3

  5. 2


Correct Option: C
Explanation:

This is the correct answer. 

Which of the following methods is not present in the List interface?

  1. indexOf(Element : e)

  2. Setthere(index,element)

  3. Get(index)

  4. Remove(index)

  5. Merge(c:collection,c1:collection)


Correct Option: E
Explanation:

There is no method named Merge(c:collection,c1:collection) in List interface.

Which of the following methods is not necessary to define for a class if it implements the windowListener interface?

  1. windowMoved()

  2. windowClosing()

  3. windowIconified()

  4. windowActivated()

  5. windowDeiconified()


Correct Option: A
Explanation:

This option is correct.

Which of the following methods is not present in the Java Collections interface?

  1. retainAll(collection c)

  2. toArray()

  3. containsAll()

  4. addAll(Collection c)

  5. First()


Correct Option: E
Explanation:

First() method is present in sortedSet interface, not in Collection interface. 

What will be the output of the above program?

Directions: Read the syntax given below and answer the question that follows.

public class If2 {
 static boolean b1, b2;
 public static void main(String [] args)
 {
  int x = 0;
 if ( !b1 ) /* Line 7 */
 {
 if ( !b2 ) /* Line 9 */
 {
 b1 = true;
 x++;
 if ( 5 > 6 )
 {
 x++;
 }
 if ( !b1 ) x = x + 10;
 else if ( b2 = true ) /* Line 19 */ x = x + 100;
 else if ( b1 | b2 ) /* Line 21 */ x = x + 1000;
 }
 }
 System.out.println(x);
 }
 }

  1. 0

  2. 1

  3. 101

  4. 111

  5. 110


Correct Option: C
Explanation:

This is the correct choice.

- Hide questions