How to instantiate an array of Map<Integer, Double> ?

I'm trying to convert legacy code to use generics.

Old data structure:

Hashtable positions[] = new Hashtable[n];

New (unsuccessful...) attempt:

Map<String, Double> positions[] = new HashMap<String, Double>()[n];

Can't get this to compile, no matter what permutation I try of <> and ().

Can someone please explain how to do it?

Thanks,

[403 byte] By [zebulaha] at [2007-10-2 10:57:19]
# 1
> I'm trying to convert legacy code to use generics.Can't try right now, but I'd guessMap<String, Double>[] positions = new HashMap<String, Double>[n];
ChristianMennea at 2007-7-13 3:23:32 > top of Java-index,Java Essentials,Java Programming...
# 2

> > I'm trying to convert legacy code to use generics.

>

> Can't try right now, but I'd guess

>

> Map<String, Double>[] positions = new

> HashMap<String, Double>[n];

Unfortunately this will not work. There are limitations when declaring generic arrays that mean you have to do something like -

Map<String, Double>[] positions = (Map<String, Double>[]) new HashMap[10];

Not very nice but ...

sabre150a at 2007-7-13 3:23:32 > top of Java-index,Java Essentials,Java Programming...
# 3
> Can someone please explain how to do it?Why not use a List?Map<String, Double> position = new HashMap<String, Double>();List<Map> allPositions = new ArrayList<Map>();
prometheuzza at 2007-7-13 3:23:32 > top of Java-index,Java Essentials,Java Programming...