What is class? How to use class?


A class is a Java class offered in commons-collections4.jar that wraps a regular map into a special map with a mechanism to automatically generate any missing entries in the map.

A LazyMap object contains a Factory object that will be used to automatically generate the value of any key that does not exist in the LazyMap object, when the get() method is called.

Here is a simple example of using class:

// Copyright (c) 2016-2018
// Supports commons-collections4-4.2
// Supports commons-collections4-4.1

import java.util.Date;
import java.util.Map;
import java.util.HashMap;
import org.apache.commons.collections4.Factory;

// Example of using the LazyMap class
public class LazyMapExample {
   public static void main(String[] args) throws Exception {
      // Create a "factory" with anonymous class
      Factory<Date> factory = new Factory<Date>() {
         public Date create() {
            return new Date();

      // Create a regular "map"
      Map<String, Date> map = new HashMap<String, Date>();
      // Wrap the regular "map" into a "lazy" map
      Map<String, Date> lazy = LazyMap.lazyMap(map, factory);

      // Generate values on the fly

      // Loop though the map
      for (String key : lazy.keySet()) {
         System.out.println(key + " = " + lazy.get(key));

You can compile and run the above example in a command window as shown below:

   -cp C:\fyicenter\commons-collections4-4.2\commons-collections4-4.2.jar

   -cp .;C:\fyicenter\commons-collections4-4.2\commons-collections4-4.2.jar 

Sat Oct 6 23:08:38 EDT 2018
Sat Oct 6 23:08:40 EDT 2018
Before = Sat Oct 6 23:08:38 EDT 2018
After = Sat Oct 6 23:08:40 EDT 2018


org.apache.commons.collections4.queue.CircularFifoQueue Example

Class Packages in commons-collections4-4.1.jar

Using commons-collections.jar in Java Programs

⇑⇑ FAQ for Apache commons-collections.jar

2017-05-20, 2697🔥, 0💬