Blog - HubSpot Product Team

Key/Value Pair Struct in .NET and JAVA

Written by Mohamed Faramawi | Jul 9, 2009

 I was proting some code from C# to Java, that code was using the struct KeyValuePair , this struct is pretty handy when you want to return a single key/value object without defining a Dictionary object that will contain only one element.

In Java there is no matching class defined in core Java APIs that match the .NET KeyValuePair class, but such class can be found in the apache.commons.collections API and its called DefaultKeyValue.

Although there is another option in Java core APIs, its the  java.util.Properties, but i didn't like it.