Java 16961 (#13236)
* [JAVA-16961] Moved code for article "Create an Empty Map in Java" * [JAVA-16961] Alter README.md * [JAVA-16961] Moved code for article "Sorting a Hashset in Java" * [JAVA-16961] Added links to README.md files * [JAVA-16961] Revert link changes * [JAVA-16961] Replaced junit4 with junit5 annotations * [JAVA-16961] test build * [JAVA-16961] Added junit annotations * [JAVA-16961] Added links Co-authored-by: panagiotiskakos <[email protected]>
This commit is contained in:
committed by
GitHub
co-authored by
panagiotiskakos
parent
4723349f37
commit
13097b458f
+62
@@ -0,0 +1,62 @@
|
||||
package com.baeldung.map;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.NavigableMap;
|
||||
import java.util.SortedMap;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
public class EmptyMapInitializer {
|
||||
|
||||
public static Map<String, String> articleMap;
|
||||
static {
|
||||
articleMap = new HashMap<>();
|
||||
}
|
||||
|
||||
public static Map<String, String> createEmptyMap() {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
public void createMapUsingConstructors() {
|
||||
Map hashMap = new HashMap();
|
||||
Map linkedHashMap = new LinkedHashMap();
|
||||
Map treeMap = new TreeMap();
|
||||
}
|
||||
|
||||
public Map<String, String> createEmptyMapUsingMapsObject() {
|
||||
Map<String, String> emptyMap = Maps.newHashMap();
|
||||
return emptyMap;
|
||||
}
|
||||
|
||||
public Map createGenericEmptyMapUsingGuavaMapsObject() {
|
||||
Map genericEmptyMap = Maps.<String, Integer>newHashMap();
|
||||
return genericEmptyMap;
|
||||
}
|
||||
|
||||
public static Map<String, String> createMapUsingGuava() {
|
||||
Map<String, String> emptyMapUsingGuava =
|
||||
Maps.newHashMap(ImmutableMap.of());
|
||||
return emptyMapUsingGuava;
|
||||
}
|
||||
|
||||
public static Map<String, String> createImmutableMapUsingGuava() {
|
||||
Map<String, String> emptyImmutableMapUsingGuava = ImmutableMap.of();
|
||||
return emptyImmutableMapUsingGuava;
|
||||
}
|
||||
|
||||
public SortedMap<String, String> createEmptySortedMap() {
|
||||
SortedMap<String, String> sortedMap = Collections.emptySortedMap();
|
||||
return sortedMap;
|
||||
}
|
||||
|
||||
public NavigableMap<String, String> createEmptyNavigableMap() {
|
||||
NavigableMap<String, String> navigableMap = Collections.emptyNavigableMap();
|
||||
return navigableMap;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user