Tangible Software Solutions

The Most Trusted Name in Source Code Conversion

C# Equivalent to Java HashMap

The nearly exact C# (or VB) equivalent to Java's HashMap collection is the .NET System.Collections.Generic.Dictionary collection.

Original Java:

void HashMaps()
{
   java.util.HashMap<String, Integer> myDictionary = new java.util.HashMap<String, Integer>();
   String s = "test";
   myDictionary.put(s, 1);
   int i = myDictionary.get(s);
   i = myDictionary.size();
   boolean b = myDictionary.isEmpty();
   myDictionary.remove(s);
}

Equivalent C#:

using System.Collections.Generic;

void HashMaps()
{
   Dictionary<string, int?> myDictionary = new Dictionary<string, int?>();
   string s = "test";
   myDictionary[s] = 1;
   int i = myDictionary[s].Value;
   i = myDictionary.Count;
   bool b = myDictionary.Count == 0;
   myDictionary.Remove(s);
}

If you need to convert from Java to C# and you are depending on the results being reliable and accurate, then you will want to have Java to C# Converter, the best Java to C# converter, at your fingertips.

Copyright © 1997 - 2017 Tangible Software Solutions Inc.