Mahipal Nehra

2 years ago · 1 min. reading time · ~10 ·

Contact the author

Like Share Comment
Mahipal blog
What is the Iterator Design Pattern?

What is the Iterator Design Pattern?

woo auoziaydioapy/:sdny

I\ sasemyog auoz Jaydioag

Learn to use the Iterator Design Pattern in Java. Iterator design pattern is a behavioural design pattern that lays down a way to access elements of a collection sequentially. It provides a way for us to implement the accessibility of elements without exposing the underlying representation of the container. A container can be a list, set, multiset, trees, and graphs, and by underlying representation we mean the way the container has been composed with its methods and properties. If you have come across iterators or “iterables” before, they are in a more general sense something that can be looped over, using a standard loop. “So, what is new in this? We can iterate over anything. Well, not really there are edge cases where we have to follow an approach such as the Iterator design pattern in order to create a clean design of our code. For understanding the magic behind iterators in java you need to understand the Iterator design pattern. In this article we are going to see what is the iterator design pattern, benefits of the iterator design pattern, and the iterator design pattern example in java.

What is the Iterator Design Pattern?

Java Provides some built-in containers to store and access the elements. For example – the Array List or a simple Array object can do that for us. Generally, we instantiate an array object and feed into the list whatever data we need to loop over later. But what if we want to create a custom list. Say, we are creating an application for a Toy Store and it has an inventory object that contains the log of items that came in and went out and also the list of toys that needs to be sold. Now, we could do that using a for loop quite easily but the thing is if in the future we may need to make modifications to our application and instead of using an array if we are to use some other iterable collection, a lot of changes would be needed. With an array we can get the size, index of the element in the array in one way, and if it were some other collection like a hash table then the way to get those properties might be different. Now, to get away with all these hassles we already have a solution for it, “the iterator design pattern”.

Read: "What is facade design pattern in Java?"

Read the the full story:
Like Share Comment

Articles from Mahipal Nehra

View blog
1 year ago · 1 min. reading time

The development of technology, storage, and processing strength has caused the embodiment of cloud c ...

2 years ago · 1 min. reading time

In the era of cloud computing, we humans have been exposed to unprecedented amounts of data which al ...

1 year ago · 2 min. reading time

Hire developers to deliver quality code for your product on hourly rate, full time contract and part ...

You may be interested in these jobs


    Acquisition Manager

    Found in: Linkedin IN Premium - 5 hours ago


    Job Role : ACQUISITION MANAGER – BUSINESS BANKING · Location : Kolkata · Qualification : - Bachelor's / Master's Degree in Business · Relevant Experience :- 2-7 years of Business Banking Sales · Job Responsibilities : · Establish new borrowing relationships for Business Banking ( ...

  • EPAM Anywhere

    Senior Automation Tester

    Found in: Linkedin IN Premium - 1 week ago

    EPAM Anywhere Pune

    We would be happy to consider your applications if you are willing to join EPAM Anywhere by 15 December 2022 inclusive ly . Applications with later onboarding dates will not be considered . · Are you a tech professional looking for remote work in a global setting? If yes, this jo ...

  • IGXGlobal

    IN- Application Developer

    Found in: Talent IN - 4 days ago

    IGXGlobal Bengaluru Full Time

    Job Description: · As an Application Developer, you will participate in all phases of the development of a large distributed system and provide hardware, manageability, operability and performance perspectives on all aspects of platform. · Job Responsibilities: · Architect sol ...