I created a class Foothat has a method toArray()that returns Array<Int>.
Now I have a HashMap string mapping for HashMaps that display objects in Foo. I.e:
HashMap<String,HashMap<Object,Foo>>
And I want to create a new object like:
HashMap<String,HashMap<Object,Array<Int>>>
This is obtained by calling the toArray () function for each Foo element in the original HashMAp.
For this, I usually do something like:
public static HashMap<String,HashMap<Object,Array<Int>>> changeMap(Map mpOld) {
Object key2;
String key1;
Iterator it2;
HashMap<String,HashMap<Object,Array<Int>>> mpNew=
new HashMap<String,HashMap<Object,Array<Int>>>()
Iterator it1 = mpOld.keySet().iterator();
while (it1.hasNext()) {
key1=it1.next();
it2= mpOld.get(key1).keySet().iterator();
mpNew.put(key1,new HashMap<Object,Array<Int>>())
while (it2.hasNext()) {
key2=it2.next();
mpNew.get(key1).put(key2,mpOld.get(key1).get(key2).toArray());
}
}
return mpNew;
}
This code works just fine, but the HashMap size is too large to hold two of them in memory. As you can see, I have added two points where I want to clear some entries. The problem is that if I do this, I get either a concurrency error, or the iterator loop just ends.
I wonder if there is a better way to iterate through Maps and copy information.
, Scala, Java . Java.util.HashMap , , Scala - , ?
,