Data Structures
- If the size of the array used to implement a circular queue is MAX_SIZE. How rear moves to traverse inorder to insert an element in the queue?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
The front and rear pointer od circular queue point to the first element.
- What is the output of below code snippet?
import java.util.*;
public class HashSet_Example
{
public static void main(String[] args)
{
Set setobj = new HashSet();
setobj.add(new Long(20));
setobj.add(new Integer(30));
for(Object object : setobj)
{
System.out.println("test - "+object);
}
}
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
Integer and Long are two different data types and different objects. So they will be treated as unique elements and not overridden.
- Set has contains(Object o) method.
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
Set has contains(Object o) method instead of get(Object o) method as get is needed for comparing object and getting corresponding value.
- What is the difference between TreeSet and SortedSet?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
SortedSet is an interface. It maintains an ordered set of elements. TreeSet is an implementation of SortedSet.
- What happens if two threads simultaneously modify TreeSet?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
TreeSet provides fail-fast iterator. Hence when concurrently modifying TreeSet it throws ConcurrentModificationException.