Constant map of constant values
If you want constant instance variable of type Map with some constant values populated in it, then you can use below way.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
package ravi.tutorial.apache.lang3; import java.util.Map; import org.apache.commons.lang3.ArrayUtils; public class ConstantMap { /** * Constant Map of constant values. */ private static final Map CONSTANT_MAP_OF_COLORS = ArrayUtils .toMap(new String[][] { { "RED", "#FF0000" }, { "GREEN", "#00FF00" }, { "BLUE", "#0000FF" } }); public static void main(String[] args) { System.out.println("Code of GREEN = " + CONSTANT_MAP_OF_COLORS.get("GREEN")); } } |
Output:
1 |
Code of GREEN = #00FF00 |