Collections
Collections
Home
Core Java Interview Questions-2 Test
Home
AJAX Questions
JSP Questions 47. How do you traverse through a collection using its Iterator?
To use an iterator to traverse through the contents of a collection,
Servlets Questions
follow these steps:
JDBC Questions Obtain an iterator to the start of the collection by calling the
Core Java Questions collection’s iterator() method.
Set up a loop that makes a call to hasNext(). Have the loop iterate
XML Questions
as long as hasNext() returns true.
Webservices Questions Within the loop, obtain each element by calling next().
EJB Questions
webMethods Questions
48. How do you remove elements during Iteration?
Tibco Questions Iterator also has a method remove() when remove is called, the current element in the iteration is deleted.
BREW Questions
UML
webMethods 52. What are the main implementations of the List interface ?
The main implementations of the List interface are as follows :
Struts
ArrayList : Resizable-array implementation of the List interface.
More....
The best all-around implementation of the List interface.
Vector : Synchronized resizable-array implementation of the List
interface with additional "legacy methods."
LinkedList : Doubly-linked list implementation of the List interface. May provide better performance than the ArrayList
implementation if elements are frequently inserted or deleted within the list. Useful for queues and double-ended queues
(deques).
58. How do you decide when to use ArrayList and When to use
LinkedList?
If you need to support random access, without inserting or removing
elements from any place other than the end, then ArrayList offers the
optimal collection. If, however, you need to frequently add and remove
elements from the middle of the list and only access the list elements
sequentially, then LinkedList offers the better implementation.
« Previous | 1 2 3 4 5 | Next »
ALSO SEE :
About Us | Our Mission | Terms of use | Author Terms | Search | Contact Us | Advertise With Us | Link to Us | Sitemap
Copyright © 2016 developersBOOK.COM. All rights reserved.