Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7543179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:21:34+00:00 2026-05-30T08:21:34+00:00

Assume I have a List<SomeObject> a . Now also assume that I have another

  • 0

Assume I have a List<SomeObject> a.
Now also assume that I have another List<SomeProcessor> b.
Each SomeProcessor uses a for its processing.

Besides:

int idx = 0;   
for(SomeProcessor o:b){  
    o2 = a.get(idx);  
    o.doSomething(o2);  
    idx++;   
}

Is there a more elegant way to handle this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T08:21:36+00:00Added an answer on May 30, 2026 at 8:21 am
    public interface Processor<T> {
        public void process(T object);
    }
    

    And then a helper method:

    public static <T> void processAll(Collection<T> items, Collection<? extends Processor<T>> processors) {
        Iterator<T> i = items.iterator();
        Iterator<? extends Processor<T>> p = processors.iterator();
        while(i.hasNext() && p.hasNext())
            p.next().process(i.next()); 
    }
    

    You could put that helper method on the class which uses it, if there is only one (and make it private), or put it a utility class which is shared by the entire program.

    Of course there are other ways to code processAll; for example, you could use a for loop on one of the collections. But in any case, breaking this low-level code out into a helper method will make your higher-level code cleaner and less “noisy”. And if you are doing something similar in multiple parts of the program, they can share the helper method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

assume that I have this list: <ul id=carousel> <li><a title=hey><img src=image.png/></a></li> </div> And now
Assume that I have a list of 100 products, each of which has a
(code examples are python) Lets assume we have a list of percentages that add
So let's assume I have a class named ABC that will have a list
In Java, assume I have the following class Container that contains a list of
Assume I have a list of IP ranges (last term only) that may or
I assume this has a simple solution. I have a list that I want
Assume I have a controller method like this: [Audit] public JsonNetResult List(int start, int
Let's assume I have 2 List<T> List1 and List2 that look like this: List
Assume I have tow lists: List<int> l1, and List<int>l2 Please help me how to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.