Drivers Category

Drivers Update
Drivers

Java collections interview questions pdf download

Version: 46.32.26
Date: 12 April 2016
Filesize: 0.835 MB
Operating system: Windows XP, Visa, Windows 7,8,10 (32 & 64 bits)

Download Now

Core Java Interview Questions-2 46. What is an Iterator? The Iterator interface is used to step through the elements of a Collection. Iterators let you process each element of a Collection. Iterators are a generic way to go through all the elements of a Collection no matter how it is organized. Iterator is an Interface implemented a different way for every Collection. 47. How do you traverse through a collection using its Iterator? To use an iterator to traverse through the contents of a collection, follow these steps: Obtain an iterator to the start of the collection by calling the collection’s iterator method. Set up a loop that makes a call to has Next. Have the loop iterate as long as has Next returns true. Within the loop, obtain each element by calling next. 48. How do you remove elements during Iteration? Iterator also has a method remove when remove is called, the current element in the iteration is deleted. 49. What is the difference between Enumeration and Iterator? Enumeration Iterator Enumeration doesn't have a remove method Iterator has a remove method Enumeration acts as Read-only interface, because it has the methods only to traverse and fetch the objects Can be abstract, final, native, static, or synchronized Note: So Enumeration is used whenever we want to make Collection objects as Read-only.50. How is List Iterator? List Iterator is just like Iterator, except it allows us to access the collection in either the forward or backward direction and lets us modify an element 51. What is the List interface? The List interface provides support for ordered collections of objects. Lists may contain duplicate elements. 52. What are the main implementations of the List interface? The main implementations of the List interface are as follows : Array List : Resizable-array implementation of the List interface. The best all-around implementation of the List.
Interview questions from Collection package or framework is most common in any Core Java Interview yet a tricky one. Together Collection and multithreading makes any Java interview tough to crack and having a good understanding of Collection and threads will help you to excel in Java interview. I thought about writing interview questions on collection when I wrote 10 multi-threading Interview questions and Top 20 Core Java Interview questions answers but somehow it got delayed. In this article we will see mix of some beginners and advanced Java Collection interviews and there answers which has been asked in various Core Java interviews. These Collection interview questions have been collected from various friends and colleagues and Answers of these interview questions can also be found by Google. 1. How Hash Map works in Java? This is Classical Java Collection interview questions which I have also discussed in How Hash Map works in Java. This collection interview questions is mostly asked during AVP Role interviews on Investment- Banks and has lot of follow-up questions based on response of interviewee e.g. Why Hash Map keys needs to be immutable, what is race conditions on Hash Map and how Hash Map resize in Java. For explanation and answers of these questions Please see earlier link. 2. What is difference between poll and remove method of Queue interface? Though both poll and remove method from Queue is used to remove object and returns head of the queue, there is subtle difference between them. If Queue is empty then a call to remove method will throw Exception, while a call to poll method returns null. By the way, exactly which element is removed from the queue depends upon queue's ordering policy and varies between different implementation, for example Priority Queue keeps lowest element as per Comparator or Comparable at head position.  3. What is.
Answer: Option Explanation: Option B is correct. A set is a collection that contains no duplicate elements. The iterator returns the elements in no particular order (unless this set is an instance of some class that provides a guarantee). A map cannot contain duplicate keys but it may contain duplicate values. List and Collection allow duplicate elements. Option A is wrong. A map is an object that maps keys to values. A map cannot contain duplicate keys; each key can map to at most one value. The Map interface provides three collection views, which allow a map's contents to be viewed as a set of keys, collection of values, or set of key-value mappings. The order of a map is defined as the order in which the iterators on the map's collection views return their elements. Some map implementations, like the Tree Map class, make specific guarantees as to their order (ascending key order others, like the Hash Map class, do not (does not guarantee that the order will remain constant over time). Option C is wrong. A list is an ordered collection (also known as a sequence). The user of this interface has precise control over where in the list each element is inserted. The user can access elements by their integer index (position in the list and search for elements in the list. Unlike sets, lists typically allow duplicate elements. Option D is wrong. A collection is also known as a sequence. The user of this interface has precise control over where in the list each element is inserted. The user can access elements by their integer index (position in the list and search for elements in the list. Unlike sets, lists typically allow duplicate elements. @ : Home > Java Programming > Objects and Collections > General Questions 7.  Which collection class allows you to associate its elements with key values, and allows you to retrieve objects in FIFO (first-in, first-out).

© 2014-2016 smarizteppa.5v.pl