Select chapter



basics (7.papers)
constructors (1.papers)
packages (1.papers)
inheritance (7.papers)
misc (3.papers)
exceptions (5.papers)
threads (4.papers)
overloading (1.papers)
jsp (3.papers)
servlets (9.papers)
jdbc (2.papers)
util (1.papers)
xml (2.papers)
IO stream (3.papers)
Hide

Sponsored Links


  

java collection framework interview questions and answers

Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
4
What is collection framework? what does java's collection framework contain?
  1. It contains interfaces which tells about the basic behavior or properties of each collection types
  2. it contains implementation part which implements various collection interfaces
  3. it contains algorithms which has some generic function implementations like sort and search which you can apply on more than one set of collection generically
  4. it contains all above 3 parts
Show Answer
Share Facebook gmail Twitter
5
which of the below are implementations of set interface?
  1. Hashset, Treeset
  2. Hashset, Treeset, LinkedHashSet
  3. TreeSet, LinkedHashSet
  4. Hashmap, treeset, linkedhashset
Show Answer
Share Facebook gmail Twitter
6
How to get or read elements from a Set?
  1. ListIterator
  2. Iterator
  3. you can use both either option1 or option 2.
  4. you have to use normal for loop
Show Answer
Share Facebook gmail Twitter
7
Which of the below are not a function of Set interface?
  1. isEmpty()
  2. add(E element)
  3. remove(Object element)
  4. get(int index)
Show Answer
Share Facebook gmail Twitter
8
What is not the property of a List interface?
  1. you can store duplicated values in lists
  2. list is an ordered collection of items.
  3. list is not an ordered collection of items.
  4. you can do positional access of an element in lists.
Show Answer
Share Facebook gmail Twitter
9
How many List interface implementations are available in collection framework of java?
  1. Array, ArrayList, LinkedList
  2. ArrayList, LinkedList
  3. ArrayList, LinkedList, Stack, Queue
  4. ArrayList, LinkedList, HashList
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
12
TreeSet vs HashSet : 
If I enter some data lets say {"skill","gun","technologies"}, and I try to read it from Treeset and hashset then in which order it will read?
  1. TreeSet: gun, skill, technologies. HashSet: It can read in any order.
  2. TreeSet: skill, gun, technologies. HashSet: it can read in any order.
  3. TreeSet: gun, skill, technologies. HashSet: skill, gun, technologies
  4. TreeSet: skill, gun, technologies. HashSet: skill, gun, technologies
Show Answer
Share Facebook gmail Twitter
13
What is the difference between Iterator and ListIterator?
  1. Iterator is super class of ListIterator
  2. ListIterator is super class of Iterator
  3. you have to use only ListIterator with List always, can't use Iterators
  4. You can use ListIterators on sets
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
15
What is the internal implementation of HashSet?
  1. It uses binary tree internally to store the set data
  2. It uses LinkedList internally
  3. it uses HashMap internally
  4. it uses hash set internally
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
17
Note : HashSet internally uses hash maps to store the values.
When set values are inserted using HashSet, does it store it as keys or values in hashmap internally?
  1. it stores as keys, as keys can't be duplicate values
  2. it stores as values, as values can't be duplicate values
  3. it can be either of option1 or 2 depends.
  4. none
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
20
java collection framework set example, with iterator remove() function:
what will be the outpout of below java program.
public class SetsDemoProgram {
        public static void main(String[] args) {
                Set<String> s = 
                               new HashSet<String>();
                s.add("about us");
                s.add("home");
                s.add("trainings");
                s.add("contact us");
                
                Iterator<String> i = s.iterator();
                while(i.hasNext()){
                        System.out.println(i.next());
                        i.remove();
                        i.remove();
                }
        }
}
  1. it prints all the elements of the set, but immediately we are removing it as well.
  2. it won't print any thing, because every loop in the iterator we are removing each element.
  3. it gives run time error,  illegalstate exception, as we are trying to remove 2 times for every time we call next() which is not valid.
  4. no error no output
Show Answer
Share Facebook gmail Twitter
Read more papers :