The Artima Developer Community
Sponsored Link

Java Buzz Forum
Top 20 collection framework interview questions and answers in java

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
instanceof java

Posts: 576
Nickname: instanceof
Registered: Jan, 2015

instanceof java is a java related one.
Top 20 collection framework interview questions and answers in java Posted: Jul 21, 2015 11:04 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by instanceof java.
Original Post: Top 20 collection framework interview questions and answers in java
Feed Title: Instance Of Java
Feed URL: http://feeds.feedburner.com/blogspot/TXghwE
Feed Description: Instance of Java. A place where you can learn java in simple way each and every topic covered with many points and sample programs.
Latest Java Buzz Posts
Latest Java Buzz Posts by instanceof java
Latest Posts From Instance Of Java

Advertisement

1.Why Map interface doesn’t extend Collection interface?

  • Set is unordered collection and does not allows duplicate elements.
  • List is ordered collection allows duplicate elements.
  • Where as Map is key-value pair.
  • It is viewed as set of keys and collection of values.
  • Map is a collection of key value pairs so by design they separated from collection interface.

2.What is difference between HashMap and Hashtable?

  • Synchronization or Thread Safe 
  • Null keys and null values 
  • Iterating the values 
  •  Default Capacity
    Click here for the
    Differences between HashMap and Hash-table

    3.Differences between comparable and comparator?

    • Comparable Interface is actually from java.lang package.
    • It will have a method compareTo(Object obj)to sort objects
    • Comparator Interface is actually from java.util package.
    • It will have a method compare(Object obj1, Object obj2)to sort objects
    Read more :  comparable vs comparator

    4.How can we sort a list of Objects?

    •  To sort the array of objects we will use  Arrays.sort() method.
    • If we need to sort collection of object we will use Collections.sort().

    5.What is difference between fail-fast and fail-safe?

    • Fail fast is nothing but immediately report any failure. whenever a problem occurs fail fast system fails. 
    • in java Fail fast iterator while iterating through collection of objects sometimes concurrent modification exception will come there are two reasons for this.
    • If one thread is iterating a collection and another thread trying to modify the collection.
    • And after remove() method call if we try to modify collection object

    6. What is difference between Iterator ,ListIterator and Enumeration?

    • Enumeration interface implemented in java 1.2 version.So Enumeration is legacy interface.
    • Enumeration uses elements() method.
    • Iterator is implemented on all Java collection classes.
    • Iterator uses iterator() method.
    • Iterator can traverse in forward direction only.
    • ListIterator is implemented only for List type classes
    • ListIterator uses listIterator() method.
    Read more :  

    What is difference between Iterator ,ListIterator and Enumeration?

    7.What is difference between Set and List in Java?

    • A set is a collection that allows unique elements.
    • Set having no index.
    • Set allows only one null value.
    • Set having classes like :
    • HashSet
    • LinkedHashMap
    • TreeSet
    • List having index.
    • List allows n number of null values.
    • List will display Insertion order with index.
    • List having classes like :
    • Vector
    • ArrayList
    • LinkedList

    8.Differences between arraylist and vector?

    • Vector was introduced in  first version of java . that's the reason only vector is legacy class.
    • ArrayList was introduced in java version1.2, as part of java collections framework.
    • Vector is  synchronized. 
    • ArrayList is not synchronized.

    9.What are the classes implementing List interface?

    • ArrayList     
    • LinkedList     
    • Vector

    10. Which all classes implement Set interface ?

    • HashSet
    • LinkedHashSet
    • TreeSet

    11.How to make a collection thread safe?

    • Vector, Hashtable, Properties and Stack are synchronized classes, so they are thread-safe and can be used in multi-threaded environment.
    • By using Collections.synchronizedList(list)) we can make list classes thread safe.
    • By using 
      java.util.Collections.synchronizedSet()  we can make set classes thread safe.

    12.Can a null element added to a TreeSet or HashSet?

    • One null element can be added to hashset.
    • TreeSet also allow null value once.

    13. Explain Collection’s hierarchy?

    14.Which design pattern Iterator follows?

    • Iterator design pattern

    15.Which data structure HashSet implements

    • Hashset implements hashmap internally.

    16.Why doesn't Collection extend Cloneable and Serializable?

    • List and Set and queue extends Collection interface.
    • SortedMap extends Map interface.

    17.What is the importance of hashCode() and equals() methods? How they are used in Java?

    • equals() and hashcode() methods defined in "object" class. 
    • If equals() method return true on comparing two objects then hashcode() of those two objects must be same.

    18.What is difference between array & arraylist?

    • Array is collection of similar type of objects and fixed in size.
    • Arraylist is collection of homogeneous and heterogeneous elements.

    19.What is the Properties class?

    • Properties is a subclass of Hashtable. It is used to maintain lists of values in which the key and the value is String.

    20.How to convert a string array to arraylist?

    • Using arrayList.toArray();


    Read: Top 20 collection framework interview questions and answers in java

    Topic: Apache Solr Synonyms Example Previous Topic   Next Topic Topic: Workshop in a Can: Setup a JBoss BRMS Full Day Workshop

    Sponsored Links



    Google
      Web Artima.com   

    Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use