Categories:
Audio (13)
Biotech (29)
Bytecode (36)
Database (77)
Framework (7)
Game (7)
General (507)
Graphics (53)
I/O (35)
IDE (2)
JAR Tools (101)
JavaBeans (21)
JDBC (121)
JDK (426)
JSP (20)
Logging (108)
Mail (58)
Messaging (8)
Network (84)
PDF (97)
Report (7)
Scripting (84)
Security (32)
Server (121)
Servlet (26)
SOAP (24)
Testing (54)
Web (15)
XML (309)
Collections:
Other Resources:
org.apache.commons.collections4.map.LazyMap Example
What is org.apache.commons.collections4.map.LazyMap class? How to use org.apache.commons.collections4.map.LazyMap class?
✍: FYIcenter.com
org.apache.commons.collections4.map.LazyMap 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 org.apache.commons.collections4.map.LazyMap class:
// Copyright (c) 2016-2018 FYIcenter.com // 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; import org.apache.commons.collections4.map.LazyMap; // 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 System.out.println(lazy.get("Before")); Thread.sleep(1000); System.out.println(lazy.get("After")); // 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:
C:\fyicenter>\fyicenter\jdk-1.8.0\bin\javac -cp C:\fyicenter\commons-collections4-4.2\commons-collections4-4.2.jar LazyMapExample.java C:\fyicenter>\fyicenter\jdk-1.8.0\bin\java -cp .;C:\fyicenter\commons-collections4-4.2\commons-collections4-4.2.jar LazyMapExample 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
2017-05-20, 2246👍, 0💬
Popular Posts:
Apache Ant is a Java-based build tool. In theory, it is kind of like make, without make's wrinkles. ...
JRE 8 rt.jar is the JAR file for JRE 8 RT (Runtime) libraries. JRE (Java Runtime) 8 is the runtime e...
JDK 11 jdk.rmic.jmod is the JMOD file for JDK 11 RMI (Remote Method Invocation) Compiler Tool tool, ...
How to download and install JDK (Java Development Kit) 8? If you want to write Java applications, yo...
What Is commons-fileupload-1.3.3 .jar?commons-fileupload-1.3.3 .jaris the JAR file for Apache Common...