diff --git a/libraries/pom.xml b/libraries/pom.xml index c7ef64bc59..a49570b029 100644 --- a/libraries/pom.xml +++ b/libraries/pom.xml @@ -373,6 +373,21 @@ eclipse-collections ${eclipse-collections.version} + + net.sf.trove4j + trove4j + 3.0.2 + + + it.unimi.dsi + fastutil + 8.1.0 + + + colt + colt + 1.2.0 + io.vavr vavr diff --git a/libraries/src/main/java/com/baeldung/primitives/PrimitiveMaps.java b/libraries/src/main/java/com/baeldung/primitives/PrimitiveMaps.java new file mode 100644 index 0000000000..4ee10997c2 --- /dev/null +++ b/libraries/src/main/java/com/baeldung/primitives/PrimitiveMaps.java @@ -0,0 +1,54 @@ +package com.baeldung.primitives; + +import cern.colt.map.AbstractIntDoubleMap; +import cern.colt.map.OpenIntDoubleHashMap; +import gnu.trove.map.TDoubleIntMap; +import gnu.trove.map.hash.TDoubleIntHashMap; +import org.eclipse.collections.api.map.primitive.*; +import org.eclipse.collections.impl.factory.primitive.*; + +public class PrimitiveMaps { + + public static void main(String[] args) { + + eclipseCollectionsMap(); + troveMap(); + coltMap(); + } + + private static void coltMap() { + AbstractIntDoubleMap map = new OpenIntDoubleHashMap(); + map.put(1, 4.5); + } + + private static void eclipseCollectionsMap() { + MutableObjectDoubleMap doubleMap = ObjectDoubleMaps.mutable.empty(); + doubleMap.put("1", 1.0d); + doubleMap.put("2", 2.0d); + + MutableObjectIntMap booleanMap = ObjectIntMaps.mutable.empty(); + booleanMap.put("ok", 1); + + MutableIntIntMap mutableIntIntMap = IntIntMaps.mutable.empty(); + mutableIntIntMap.addToValue(1, 1); + + ImmutableIntIntMap immutableIntIntMap = IntIntMaps.immutable.empty(); + + MutableObjectIntMap intObject = ObjectIntMaps.mutable.empty(); + intObject.addToValue("price", 2); + } + + private static void troveMap() { + + double[] doubles = new double[] {1.2, 4.5, 0.3}; + int[] ints = new int[] {1, 4, 0}; + + TDoubleIntMap doubleIntMap = new TDoubleIntHashMap(doubles, ints); + + doubleIntMap.adjustValue(1.2, 1); + doubleIntMap.adjustValue(4.5, 4); + doubleIntMap.adjustValue(0.3, 0); + + System.out.println(doubleIntMap); + } +}