Skip to content

Instantly share code, notes, and snippets.

@brianm
Created October 19, 2009 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brianm/213477 to your computer and use it in GitHub Desktop.
Save brianm/213477 to your computer and use it in GitHub Desktop.
import java.util.Map;
import java.util.LinkedHashMap;
public class Collectiony
{
public static <T> Map<T, T> LHMap(T... elements)
{
LinkedHashMap<T, T> rs = new LinkedHashMap<T, T>();
for (int i = 0; i < elements.length; i += 2) {
rs.put(elements[i], elements[1+1]);
}
return rs;
}
}
import junit.framework.TestCase;
import java.util.Map;
import static Collectiony.LHMap;
public class TestCollectiony extends TestCase
{
public void testFoo() throws Exception
{
Map<String, String> stuff = LHMap("Brian", "Colorado",
"Martin", "California");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment