Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: None  |  size: 0.58 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import java.util.Date;
  2. import java.util.Map;
  3. import java.util.HashMap;
  4.  
  5. public class FooMap {
  6.         public static <K, V> Map<K, V> map(Object ... items) {
  7.                 Map<K, V> m = new HashMap<K, V>();
  8.  
  9.                 // potentially off by 1, but this is just a test anyway.
  10.                 for (int i = 0; i < items.length; i += 2) {
  11.                         m.put((K)items[i], (V)items[i+1]);
  12.                 }
  13.                 return m;
  14.         }
  15.  
  16.         public static void main(String args[]) {
  17.                 Map<String, Date> m = map("Foo", new Date(), "Foo3", new Date());
  18.         }
  19. }