Skip to main content

Java Iterator



In Java, Iterator is an interface available in Collection framework in java.util package. It is a Java Cursor used to iterate a collection of objects.
  • It is used to traverse a collection object elements one by one.
  • It is available since Java 1.2 Collection Framework.
  • It is applicable for all Collection classes. So it is also known as Universal Java Cursor.
  • It supports both READ and REMOVE Operations.
  • Compare to Enumeration interface, Iterator method names are simple and easy to use.

Java Iterator Methods

In this section, we will discuss about Java Iterator methods in-brief. We will explore these methods in-depth with some useful examples in the coming section.
  • boolean hasNext():Returns true if the iteration has more elements.
  • E next(): Returns the next element in the iteration.
  • default void remove(): Removes from the underlying collection the last element returned by this iterator.
  • default void forEachRemaining(Consumer action): Performs the given action for each remaining element until all elements have been processed or the action throws an exception.

Advantages of Java Iterator

Compare to Enumeration interface, Java Iterator has the following advantages or benefits.
  • We can use it for any Collection class.
  • It supports both READ and REMOVE operations.
  • It is an Universal Cursor for Collection API.
  • Method names are simple and easy to use them.

Limitations of Java Iterator

However, Java Iterator has the following limitations or drawbacks.
  • In CRUD Operations, it does NOT support CREATE and UPDATE operations.
  • It supports only Forward direction iteration that is Uni-Directional Iterator.
  • Compare to Spliterator, it does NOT support iterating elements parallel that means it supports only Sequential iteration.
  • Compare to Spliterator, it does NOT support better performance to iterate large volume of data.
To overcome these limitations, Java has introduced two more Cursors: ListIterator and Spliterator. We will discuss about these two cursors in my coming posts.

Comments

Popular posts from this blog

Variables

Variables The main way to store information in the middle of a PHP program is by using a variable. Here are the most important things to know about variables in PHP. All variables in PHP are denoted with a leading dollar sign ($). The value of a variable is the value of its most recent assignment. Variables are assigned with the = operator, with the variable on the left-hand side and the expression to be evaluated on the right. Variables can, but do not need, to be declared before assignment. Variables in PHP do not have intrinsic types - a variable does not know in advance whether it will be used to store a number or a string of characters. Variables used before they are assigned have default values. PHP does a good job of automatically converting types from one to another when necessary. PHP variables are Perl-like. PHP has a total of eight data types which we use to construct our variables − Integers  − are whole numbers, without a decima...

SQL Server - INTERSECT Operator

Description The SQL Server (Transact-SQL) INTERSECT operator is used to return the records that are in common between two SELECT statements or data sets. If a record exists in one query and not in the other, it will be omitted from the INTERSECT results. It is the intersection of the two SELECT statements. Intersect Query Explanation:  The INTERSECT query will return the records in the blue shaded area. These are the records that exist in both Dataset1 and Dataset2. Each SELECT statement within the SQL Server INTERSECT must have the same number of columns in the result sets with similar data types. Syntax The syntax for the NTERSECT operator in SQL Server (Transact-SQL) is: SELECT expression1, expression2, ... expression_n FROM tables [WHERE conditions] INTERSECT SELECT expression1, expression2, ... expression_n FROM tables [WHERE conditions]; Parameters or Arguments expressions The columns or calculations that you wish to compare between the two SELECT ...

About Application

The product is supposed to be an open source application, developed under the PRSC(Punjab Remote Sensing Centre)organization, for the usage of PUDA(Punjab Urban Planning and Development Authority ). It is An android based system implementing client-server model. The Po portal System provides simple mechanism for the Planning officer to share  truly verified report. The following are the main features that are included in the application are: Common platform support: Offers operating support for most of the known and commercial operating systems i.e. android operating system. Number of users being supported by the system: Though the number is precisely not mentioned but the system is able to support a large number of online users at a time. Search: search for the pending list of the cases assigned is generally by logging in to the application. Id system: provides each officer with a unique Id which is sent at the time of report submission. Verification  section: Verif...