Core Java - Interview Questions and Answers for 'Collection' | Search Interview Question - javasearch.buggybread.com
Javasearch.buggybread.com

Search Interview Questions


 More than 3000 questions in repository.
 There are more than 900 unanswered questions.
Click here and help us by providing the answer.
 Have a video suggestion.
Click Correct / Improve and please let us know.
Label / Company      Label / Company / Text

   



Interview Questions and Answers - Order By Newest

   next 30
 Q101. Which of the collections allows null as the key ?

a. HashTable
b. HashMap
c. TreeMap
d. LinkedHashMap
Core Java
Ans. HashMap

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   collections   map  hashtable     Asked in 2 Companies      basic        frequent


 Q102. Effective Java 6 , TreeMap implements ...

a. Map Interface
b. SortedMap Interface
c. NavigableMap Interface
d. SortedNavigableMap Interface
Ans. SortedMap Interface

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   collections   map


 Q103. Can we add more elements to an array list that has been marked as final ?
Ans. Yes, the array list can hold more elements. Final only puts the restriction that the array list reference cannot hold any other array list.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     ebay   collections   arraylist   final keyword


 Q104. Write a method to convert all elements of a set to lower case.Core Java
Ans. http://javasearch.buggybread.com/CodeSnippets/searchCodeSamples.php?keyword=Method+to+convert+all+elements+of+a+collection&category=code

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     code  coding  string  String.toLowerCase  set  collections


Recently asked in Sophos
 Q105. Write a Method to get a map of words and their count by passing in the stringCore Java
Ans. http://javasearch.buggybread.com/CodeSnippets/searchCodeSamples.php?keyword=Method+to+get+a+map+of+words&category=code

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     map  collections     Asked in 2 Companies      intermediate


 Q106. Have you ever looked into internal implementation of Java Collections ?
Ans. Yeah, I once looked into implementation of TreeSet and TreeMap just for learning.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     collections


 Q107. Write code to sort elements of a set
Ans. http://javasearch.buggybread.com/CodeSnippets/searchCodeSamples.php?&category=code&searchOption&keyword=952

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     set  collections  sorting  treeset  code  coding


 Q108. What is unmodifiable set / unmodifiable map ? How can we create one ?
Ans. It is an unmodifiable / read only view of the underlying collection. We can use

Collections.unmodifiableSet(Set set)
Collections.unmodifiableMap(Map map)
Collections.unmodifiableCollection(Collection collection)

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     collections  set  unmodifiable set  map  unmodifiable map  unmodifiablemap  unmodifiableset  Collections.unmodifiableCollection  Collections.unmodifiableMap  Collections.unmodifiableSet


  Q109. What is a Destructor ? Do we have Destructors in Java ?Core Java
Ans. Destructor is used to de-allocate memory allocated by objects.

There are no destructors in Java. Alternatively, Java provides Automatic garbage collection i.e automatically releasing the un-referenced memory.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     destructor  garbage collection     Asked in 11 Companies      Basic        frequent

Try 1 Question(s) Test


 Q110. Is Iterator a class ?
Ans. No, iterator is an interface that is used to parse through the elements of a Collection

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     collections  iterator


 Q111. Which data structure would you recommend for ordered and sorted data?Core Java
Ans. TreeSet and TreeMap are used for maintaining sorted elements.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     ordered collections  sorted collections     Asked in 1 Companies      basic        frequent


 Q112. Does an ArrayList allow elements of different types ? If not, Why the following code works List list1 = new ArrayList<>(); list1.add(1); list1.add("1");Core Java
Ans. With Java 7 or Later. If you don't declare the list to be of specific type , it treats it as list of objects. int 1 is auto boxed to Integer and "1" is String and hence both are objects.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     arraylist  list  collections


 Q113. What is IdentityHashMap ?Core Java
Ans. IdentityHashMap is a class that implements AbstractMap and provides a data structure with Elements having Key Value pair, just like HashMap. It is similar to HashMap except that it uses reference equality when comparing elements.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     IdentityHashMap  map  hashmap  collections


 Q114. What is meant by size and index of a collection ?Core Java
Ans. As the name suggest size is the size of collection / data structure i.e number of elements or memory utilized by the collection.

Index is the position of an element in a collection or data structure.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     collection  index of collection  size of collection      Basic


 Q115. Why Collection interface does not extend Cloneable interface ?Core Java
Ans. Here is the list of classes that implements Collections Interface - http://www.buggybread.com/2015/02/java-collections-classes-that-implement.html

Having Collection interface to extend Cloneable interface would mean necessarily implement clone method by all implementing classes. As not all collection classes allow duplicate elements, it makes no sense to clone elements for them.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     cloneable  collections  collection interface  cloning


 Q116. Which is the root interface of Collection classes in Java ?Core Java
Ans. java.util.Collection

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     collection interface  collections


 Q117. Explain what happens when insertion is performed in case of ArrayList and LinkedList.Data Structure
Ans. Array List works on Array and when we add an element in middle of the list, Array List need to update the index of all subsequent elements. I the capacity is full, it even may need to move the whole list to a new memory location . Linked List works on Double linked list algorithm and all it has to do is to adjust the address of the previous and next elements.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     arraylist vs linkedlist  collections  list     Asked in 2 Companies


 Q118. What is the difference between Collections.emptyList() and creating new instance of List using new ?Core Java
Ans. But Collections.emptyList() returns an Immutable list whereas new arraylist() creates a mutable list.

Advantage of getting an empty list using Collections.emptyList is that it returns a singleton list which can be shared among many references and hence made immutable. This is good fit for situations where we would like to initialize a list to basic minimum empty to avoid null pointer exception.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     collections  Collections.emptyList  immutable  immutability  immutability


 Q119. Which is better in terms of performance - Iterator or Spliterator ?Core Java
Ans. Spliterator has better performance potential than iterators but only if the potential is used. Spliterator can iterate streams in parallel as well as in sequence whereas iterator can only iterate in sequence.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     iterator  collections  streams  parallel streams  Spliterator


 Q120. What are Collection Classes ?Core Java
Ans. Collections in java is a framework of classes that provides an abstracted data structure to store and manipulate the group of objects. Each class is unique in the way it stores , search , sort and modify the elements.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     collections  collection classes     Asked in 1 Companies      Basic        frequent


 Q121. What kind of thread is garbage collection thread ?Core Java
Ans. Daemon thread

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     garbage collection      intermediate

Try 2 Question(s) Test


 Q122. Do you feel that its useless to define hashCode method for a class ?Core Java
Ans. Yes its useless if we are not going to use its objects within Hash collection, For example - HashSet , HashMap. HashCode is used internally by these collections for Search.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     hashcode  hash collections  search


 Q123. What is memory leak ? How Java helps countering memory leaks compared to C++ ?Core Java
Ans. Memory Leak is a situation wherein we have a reserved memory location but the program has lost its reference and hence has no way to access it.

Java doesn't have concept of Pointers, Moreover Java has concept of Garbage collection that frees up space in heap that has lost its references.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     memory leak  garbage collection      intermediate        frequent


 Q124. What is the difference between circular queue and priority queue ?Data Structures
Ans. https://qr.ae/TWK2Ok

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     circular queue  priority queue  queue  data structures  collections


 Q125. Difference between concurrentHashMap and HashTable ?Core Java
Ans. HashTable locks the complete collection to provide synchronization whereas ConcurrentHashMap only locks segments to achieve synchronization and hence better efficient and faster.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     concurrentHashMap  HashTable  Map  Collections     Asked in 2 Companies


 Q126. isnt the use of HashTable and ConcurrentHashMap the same, i.e providing synchronized map collection ?Core Java
Ans. Yes, they both aim at providing synchronized access to the Map collection. The only difference is in their implementation. ConcurrentHashMap came after HashTable and hence technically more efficient as it doesn't lock the complete map while accessing it.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     HashTable  ConcurrentHashMap  map  Collections


 Q127. Why don't Java objects have destructors ?Core Java
Ans. Java manages memory using built-in garbage collector

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     destructor  garbage collection


 Q128. Why do we need Garbage collection ?Core Java
Ans. Garbage collection mechanism frees up the memory that is no longer needed. In languages like C / C++ the deallocation needs to be done explicitly by the programmer and hence any leniency may result in memory leak. Garbage collection in java ensures that all unused memory is reclaimed and hence there are no memory leaks.Moreover it relieves the programmer from the hassle of carefully releasing all memory.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     Garbage Collection  memory management     Asked in 2 Companies


 Q129. How is garbage collection in Java 8 different from Java 7 ? Core Java
 This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     memory management  garbage collection


 Q130. What is the difference between Enumeration and Iterator ?Core Java
Ans. Enumeration can iterate only legacy collections like Vector , HashTable and Stack whereas Iterator can iterate both legacy and non legacy collections.

Enumeration is less safer than Iterator

Enumeration is fail safe whereas Iterator is fail fast

Iterator allows for removal of element while traversal whereas Enumeration doesn't have remove method.

Enumerations were introduced in Java 1 whereas Iterators were introduced with Java 2

Enumerations have methods like hasMoreElements and nextElement whereas Iterators have methods like hasNext, next and remove

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     enumeration vs iterator  collections      Basic        frequent


previous 30   next 30

Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.

Company Name:
Questions Asked: