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

  • SEARCH
  • Home
  • 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 4084200
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:24:34+00:00 2026-05-20T18:24:34+00:00

2 collections are given with the same number of elements, say List<String> . What

  • 0

2 collections are given with the same number of elements, say List<String>. What are elegant ways in JAVA to apply a functor on each 2 elements of collections with corresponding indexes?

Say, one example could be:
List<String> = { "APPLE", "PEAR" };
List<String> = { "BANANA", "ORANGE" };

A predicate that joins string together will result in the following List<String>:
List<String> = { "APPLEBANANA", "PEARORANGE" };

  • 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-20T18:24:35+00:00Added an answer on May 20, 2026 at 6:24 pm

    Akin to the functors found in Apache Commons Collections, I have created binary equivalents in the past.

    For your situation, a binary transformer type object, which takes to two input objects and returns a single object, could be used. Here is some sample code that’s conveys my approach:

    // tranformer
    interface BinaryTransformer<X, Y, Z> {
      Z transform(X a, Y b);
    }
    
    // implementation for your problem
    class ConcatTransformer implements BinaryTransformer<String, String, String> {
      public String transform(String a, String b) {
        return a + b;
      }
    }
    
    // general use transformer
    class BinaryListUtils {
      public static <X, Y, Z> List<Z> collect(List<X> aList, List<Y> bList, BinaryTransformer<X, Y, Z> t) {
        List<Z> ret = new ArrayList<Z>(aList.size());
        Iterator<X> aIter = aList.iterator();
        Iterator<Y> bIter = bList.iterator();
        while(aIter.hasNext()) {
          ret.add(t.transform(aIter.next(), bIter.next()));
        }
      }
    }
    

    HTH

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

Sidebar

Related Questions

I've got a System.Generic.Collections.List(Of MyCustomClass) type object. Given integer varaibles pagesize and pagenumber, how
The Java Collections class has the following method: static <T> List<T> nCopies(int n, T
I can see that Collections.unmodifiableSet returns an unmodifiable view of the given set but
Following class structure is given: class Job { String description; Collection<JobHistory> history; } class
I am currently using TcpListener to address incoming connections, each of which are given
Say I create two sets of tuples like so: Dim losSPResults As List(Of spGetDataResults)
I had quite a big list of numbers. I needed to apply some operation
Given two IEnumerable s of the same size, how can I convert it to
im getting a CFDictionaryAddValue(): immutable collection 0xd5aea0 given to mutating function error when i
Given a collection of user specified tags how do I determine which ones are

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.