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

I have a class, the outline of which is basically listed below. import org.apache.commons.math.stat.Frequency;
Is there a way in Apache Commons Collections to have a PredicatedList (or similar)
The Java class CircularFifoBuffer in the package org.apache.commons.collections.buffer is non-generic, and can store objects
We have a module which will send reminder mail. We are using apache commons
I am using Apache Commons Collections to create a MultiKeyMap that will store two
I'm looking for a JavaScript data structure like ListOrderedMap: http://commons.apache.org/collections/apidocs/org/apache/commons/collections/map/ListOrderedMap.html E.g. It needs to
I am trying to use org.apache.commons.collections.CollectionUtils in android with following code import java.util.ArrayList; import
Is there a method in JDK or apache commons to pop a list of
I'm new to web java programming. I need to use this package org.apache.commons.collections .
Are there convenience methods for sorting arrays and collections that support method chaining in

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.