Mahipal Nehra

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

Blogging
>
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:  https://www.decipherzone.com/blog-detail/iterator-design-pattern
Comments

Articles from Mahipal Nehra

View blog
3 years ago · 1 min. reading time

We are living in a world that is on the verge of Industry 4.0 or the fourth industrial revolution. A ...

3 years ago · 1 min. reading time

Microservices architecture enables a system to be divided into multiple smaller, individual and inde ...

3 years ago · 2 min. reading time

https://www.decipherzone.com/blog-detail/docker-microservices · Gone are the days where there was e ...

You may be interested in these jobs

  • Direct apply

    Barclays Pune, Maharashtra, India

    Job Title : TM Risk and Governance · Location: Pune · About Barclays · Barclays is a British universal bank. We are diversified by business, by different types of customers and clients, and by geography. Our businesses include consumer banking and payments operations around the w ...

  • Shiva Systems & Technologies Private Limited

    Product Analyst

    6 days ago


    Shiva Systems & Technologies Private Limited Mumbai, India Internship, Full time

    · About the internship: · Selected intern's day-to-day responsibilities include: · 1. Find out CAD companies globally · 2. Search CAD Software with advanced Google search · > · Only those candidates can apply who: · 1. are available for full time (in-office) internship · 2. ca ...

  • SHREE CONSULTANTS

    Travel Sales Agent

    1 day ago

    Direct apply

    SHREE CONSULTANTS Delhi, India

    Very good communication Skills · - Roaster offs · - Create PNR's, make reservations and sell airline tickets · - Making Sales on inbound calls · - Worked on GDS Amadeus · maximum salary 45 · HR Recruiter · **Job Types**: Full-time, Regular / Permanent, Fresher · **Salary**: ₹20, ...