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 3679226
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T03:26:04+00:00 2026-05-19T03:26:04+00:00

In apache.commons.collections there is a class called MapUtils which have these two methods to

  • 0

In apache.commons.collections there is a class called MapUtils which have these two methods to define a Map which can create on demand objects for the map:

  • lazyMap(Map,Factory)
  • lazyMap(Map,Transformer)

So I can use a factory to instantiate the object

Factory factory = new Factory() {
    public Object create() {
        return new Object();
    }
}

or a transformer to instantiate the new object depending on the key of the map

Transformer factory = new Transformer() {
    public Object transform(Object mapKey) {
        return new Object(mapKey);
    }
}

There’s a similar class for Lists: ListUtils, but this class only has a method with a Factory:

  • lazyList(List list, Factory factory)

I’d like to transform the object like in the map situation but using the index of the object in the list instead of the key in the map.

Transformer factory = new Transformer() {
    public Object transform(int index) {
        return new Object(index);
    }
}

My question is why there is not a lazyList(List list, Transformer transformer)? Does apache provide any other List to do this or do I have to build my custom implementation?

Thanks.

  • 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-19T03:26:05+00:00Added an answer on May 19, 2026 at 3:26 am

    First of all, in my opinion you should use Guava for this sort of thing… it makes full use of generics and provides a much more well thought-out, compact and sensible API. It also provides a Lists.transform method which transforms an underlying List based on the elements at each position in the list.

    That said, I don’t think a transform method for transforming a List by index makes much sense. The actual underlying List would be completely meaningless given that the transformation would ignore the elements it contains… only its size would matter. Could you explain why you would want to do something like that?

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

Sidebar

Related Questions

Is there a way in Apache Commons Collections to have a PredicatedList (or similar)
I'm trying to use the StringEscapeUtils.escapeXML() function from org.apache.commons.lang... There are two versions of
Hi i am using commons collections generics 4.01. I have a dto object. Class
I am new to apache commons-exec. Is there a way I can send a
I am using the Apache Commons math.Fraction class to convert my doubles to fractions,
I want to extend a base class in apache commons email, the base class
Is there something like this in any standard library (e.g. apache-commons, guava) ? public
i am using the apache commons httpclient in a lotus notes java agent and
I'm using the Apache Commons EqualsBuilder to build the equals method for a non-static
I am using the Apache Commons IO: FileUtils.copyFileToDirectory(srcFile, destDir) How do I make Windows

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.