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

Microservice Architecture or Microservices are increasingly being used in the software industry to c ...

3 years ago · 2 min. reading time

Machine Learning (ML) and Artificial Intelligence (AI) technologies have gained increasing popularit ...

3 years 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

  • Alight

    Level L2 –Finance

    Found in: beBee S2 IN - 14 hours ago


    Alight Kochi, India OTHER

    This role will be an integral part of a finance team dedicated to providing support to our growing operations. This role will actively manage the Country/ Entity Finance by producing and presenting insightful analysis that supports book closure and decision making. The successful ...

  • Green Oasis Tours & Travels Services P

    Tour Executive

    Found in: Talent IN 2A C2 - 14 hours ago


    Green Oasis Tours & Travels Services P Kochi, India

    Company Description · Green Oasis Tours & Travels Pvt Ltd is a professionally managed destination management company with over 18 years of experience in the field of Travel & Tourism. Based in Kochi, Kerala, Green Oasis focuses on innovation in global tourism. The company offers ...

  • Suretek Infosoft Pvt. Ltd.

    Net Developer

    Found in: Talent IN 2A C2 - 14 hours ago


    Suretek Infosoft Pvt. Ltd. Noida, India

    Job Description : · Strong experience in either one of the frameworks -.Net core or .Net framework versions. · - Good experience in .NET Framework 4.5 and above · - Strong work experience in Dot Net Core, C#, ASP.Net, ASP.Net MVC, ADO .Net etc · - Strong work experience in object ...