Data Structures


  1. 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?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    The front and rear pointer od circular queue point to the first element.


  1. 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);
    }
    }
    }











  1. 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.



  1. Set has contains(Object o) method.











  1. 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.


  1. What is the difference between TreeSet and SortedSet?











  1. 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.



  1. What happens if two threads simultaneously modify TreeSet?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    TreeSet provides fail-fast iterator. Hence when concurrently modifying TreeSet it throws ConcurrentModificationException.