Data Retrieving Technique in Collection Framework

Advertisements

Prev Tutorial Next Tutorial

Data Retrieving Technique form Collection Framework

Technique to retrieve elements from Collection object

Java support following technique to retrieve the elements from any collection object.

  1. foreach loop
  2. Iterator interface
  3. ListIterator interface
  4. Enumeration interface

foreach

It is similar to for loop used to retrieve elements of collection objects (until the last element)

Syntax

for(datatype variable:collection-object)
{
.....
.....
}

Iterator interface

It is one of the predefined interface present in java.util.* package. The purpose of this interface is that to extract or retrieve the elements of collection variable only in forward direction but not in backward direction. By default an object of iterator is pointing just before the first element of any collection framework variable.

Methods of Iterator Interface

  • public boolean hasNext()
  • public object next()

ListIterator interface

It is one of the predefined interface present in java.util.* package. The ListIterator interface object is always used for retrieving the data from any collection framework either forward direction or backward direction or in both direction. Like Iterator interface object, ListIterator interface object is pointing just before the first element of any collection framework variable.

Methods of ListIterator Interface

  • public boolean hasNext()
  • public object next()
  • public boolean nestPrevious()
  • public object previous()

Enumeration interface

It is one of the predefined interface and whose object is always used for retrieving the data from any legacy collection framework variable only in forward direction but not in backward direction. Like Iterator interface object, Enumeration Interface object is pointing just before the first element of any legacy collection framework variable.

The functionality of Enumeration is more or less similar to Iterator Interface but Enumeration Interface object belongs to synchronized and Iterator Interface object belong to non-synchronized.

Methods of Enumeration Interface

  • public boolean hasMoreElements()
  • public object nextElement()

Prev Tutorial Next Tutorial

Google Advertisment

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 9999595223

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

For Projects 9999595223

Google Advertisements


Buy Websites 9999595223

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs

Advertisements