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
 Q71. What will be the output of this code ?

Set mySet = new TreeSet();
mySet.add("4567");
mySet.add("5678");
mySet.add("6789");
for(String s: mySet){
System.out.println(s);
}
Ans. 4567
5678
6789

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

   Like         Discuss         Correct / Improve     java   collections   set   treeset   coding   code


 Q72. public enum Day {
SUNDAY, MONDAY, TUESDAY, WEDNESDAY,
THURSDAY, FRIDAY, SATURDAY
}

public class Test {
Set mySet = new HashSet();
mySet.add(Day.MONDAY);
mySet.add(Day.SUNDAY);
mySet.add(Day.SATURDAY);

for(Day d: mySet){
System.out.println(d);
}
}
Ans. SUNDAY
MONDAY
SATURDAY

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

   Like         Discuss         Correct / Improve     enum   set   collections   hashset   coding   code

Try 3 Question(s) Test


 Q73. How is HashSet maintained in memory by Java ?Core Java
Ans. HashSet is maintained as HashMap by Java with values of the HashSet as Keys of the HashMap and value of the HashMap as the constant PRESENT.

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

   Like         Discuss         Correct / Improve     ebay  java   collections   hashset   hashmap      expert


 Q74. What is ConcurrentLinkedDeque ?Core Java
Ans. It's a Collections concrete class that provides implementation of a Double Ended queue that allows concurrent insertion, removal, and access operations that can be executed safely across multiple threads.

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

   Like         Discuss         Correct / Improve     java   collections   queue   deque   concurrent collections


 Q75. What is CopyOnWriteArrayList ?
Ans. Its a type of ArrayList in which all Write operations , i.e add and set are performed by creating a new copy. This array never changes during the lifetime of the iterator, so it never throws ConcurrentModificationException

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

   Like         Discuss         Correct / Improve     java   collections   list   arraylist   copyonwritearraylist   ConcurrentModificationException     Asked in 1 Companies


 Q76. What are the advantages and disadvantages of CopyOnWriteArrayList ?Core Java
Ans. This collections class has been implemented in such a manner that it can never throw ConcurrentModificationException. As it performs update and write operations by creating a new copy of ArrayList, It's slower compared to ArrayList.

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

   Like         Discuss         Correct / Improve     java   collections   list   arraylist   copyonwritearraylist   advantages-disadvantages   ConcurrentModificationException     Asked in 4 Companies      Expert


 Q77. Name few Concurrent Collection Classes ?
Ans. ConcurrentHashMap
ConcurrentLinkedDeque
ConcurrentLinkedQueue
ConcurrentMap
ConcurrentNavigableMap
ConcurrentSkipListMap
ConcurrentSkipListSet

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

   Like         Discuss         Correct / Improve     java   collections   concurrent collections


 Q78. Name few Collections Map implementations ?
Ans. AbstractMap
ConcurrentHashMap
ConcurrentSkipListMap
EnumMap
HashMap
IdentityHashMap
LinkedHashMap
SystemFlavorMap
TreeMap
WeakHashMap

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

   Like         Discuss         Correct / Improve     java   collections   map


 Q79. Name few interfaces that extends Collection Interface ?
Ans. http://www.buggybread.com/2015/02/java-collections-interfaces-that.html

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

   Like         Discuss         Correct / Improve     java   collections   collection interface


 Q80. Name few classes that extends Collections class ?
Ans. http://www.buggybread.com/2015/02/java-collections-classes-that-inherit.html

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

   Like         Discuss         Correct / Improve     java   collections   collections class


 Q81. Name few abstract classes of Java collections framework ?
Ans. http://www.buggybread.com/2015/02/java-collections-abstract-classes.html

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

   Like         Discuss         Correct / Improve     java   collections


 Q82. Name few classes that implement Set interface ?
Ans. http://www.buggybread.com/2015/02/java-collections-classes-that-implement_78.html

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

   Like         Discuss         Correct / Improve     java   collections   set


 Q83. Name few classes that implement iterable interface ?
Ans. http://www.buggybread.com/2015/02/java-collections-classes-that-implement_45.html

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

   Like         Discuss         Correct / Improve     java   collections   iterable


 Q84. Name few classes that implement Map interface ?
Ans. http://www.buggybread.com/2015/02/java-collections-classes-that-implement_82.html

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

   Like         Discuss         Correct / Improve     java   collections   map


 Q85. Name few classes that implement List interface ?
Ans. http://www.buggybread.com/2015/02/java-collections-classes-that-implement_35.html

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

   Like         Discuss         Correct / Improve     java   collections   list


 Q86. Name few classes that implement Queue interface ?
Ans. http://www.buggybread.com/2015/02/java-collections-classes-that-implement_1.html

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

   Like         Discuss         Correct / Improve     java   collections.queue


 Q87. Name few classes that implement Collection interface ?
Ans. http://www.buggybread.com/2015/02/java-collections-classes-that-implement.html

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

   Like         Discuss         Correct / Improve     java   collections   collection interface


 Q88. Name few Hash collections classes and interfaces ?
Ans. http://www.buggybread.com/2015/01/java-hash-collections-classes-and.html

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

   Like         Discuss         Correct / Improve     java   collections   hash collections


 Q89. Name few Queue classes and interfaces ?
Ans. http://www.buggybread.com/2015/01/java-collections-queue-classes-and.html

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

   Like         Discuss         Correct / Improve     java   collections   queue


 Q90. What are few iterator classes provided by Java ?
Ans. http://www.buggybread.com/2015/01/java-iterator-classes-and-interfaces.html

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

   Like         Discuss         Correct / Improve     java   collections   iterator


 Q91. Which sorting algorithm is used by Collections.sort() in Java ?Core Java
Ans. The sorting algorithm is a modified mergesort. This algorithm offers guaranteed n log(n) performance.

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

   Like         Discuss         Correct / Improve     java   algorithm   collections   collections.sort   sorting algorithm      expert

Try 1 Question(s) Test


 Q92. Difference between HashMap and WeakHashMap ?
Ans. WeakHashMap uses weak reference for keys, which means if the key object doesn't have any reference then both key/value mapping will become eligible for garbage collection.

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

   Like         Discuss         Correct / Improve     java   collections   hashmap   weakhashmap   difference between   garbage collection   ebay


 Q93. Which tree is used to implement TreeMap in Java?
Ans. Red Black Tree

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

   Like         Discuss         Correct / Improve     java   collections   treemap   map      expert


 Q94. What is collision in hash collections ?Core Java
Ans. Collision is the situation when two different elements have the same Hash Code.

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

   Like         Discuss         Correct / Improve     java   collections   collision   hashcode  hash code   hash collections   ebay     Asked in 1 Companies      intermediate        frequent


 Q95. What will the following code result ?

List> intList = new ArrayList>();

intList.add(Optional.empty());
intList.add(Optional.of(2));
intList.add(Optional.of(3));
intList.add(Optional.of(4));

System.out.println(intList.get(null));
Ans. Compile time error at last line as the get method expect argument of type native int.

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

   Like         Discuss         Correct / Improve     arraylist   list   coding   collections


 Q96. What will the following code result ? Will it compile ?

List> intList = new ArrayList>();

intList.add(Optional.empty());
intList.add(Optional.of(2));
intList.add(Optional.of(3));
intList.add(Optional.of(4));

System.out.println(intList.get((Integer)null));
Ans. Yes but the last line will throw NullPointerException upon execution.

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

   Like         Discuss         Correct / Improve     collections   arraylist   list   coding


 Q97. Do you know of any facility to convert between Scala and Java Util Collections ?Scala
Ans. We can use JavaConversions which is a part of Scala Library.

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

   Like         Discuss         Correct / Improve     scala   scala collections   java collections


 Q98. If we add Enum constants to a sorted collection ( Treemap , TreeSet ), What will be the order in which they will be maintained ?

a. Sorted Collection wont maintain them in any order.
b. Insertion Order
c. Order in which constants are declared.
d. Natural Sorting Order.
Ans. Order in which constants are declared.

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

   Like         Discuss         Correct / Improve     enum   collections   sorted collections   treemap   treeset   compareto   comparable   java


 Q99. Which interface does java.util.Hashtable implement ?

a. List
b. Set
c. Collection
d. Map
Core Java
Ans. Map

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

   Like         Discuss         Correct / Improve     hashtable   java   collections


 Q100. Which of the following is false ?

a. HashMap came before HashTable.
b. HashMap allows null values whereas Hashtable doesn’t allow null values.
c. HashTable and HashMap allow Key-Value pairs.
d. Hashtable is synchronized whereas HashMap is not.
Ans. HashMap came before HashTable.

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

   Like         Discuss         Correct / Improve     map   hashmap   hashtable   collection   java

Try 2 Question(s) Test


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: