java map help
ok, so in my code in the constructor, i'm taking in a set and map and using them to create another map. the new map is going to contain all the number of times all the different types of Strings in the old map appear. (like object {A, D, C, B, E} with key 5 meaning that A, D, C, B, E appears 5 times in the old map. heres my code(*note; the main isnt here):
[PHP]/*Election*/
import java.util.*;
public class Election
{ private Map<Integer, String> totals = new HashMap<Integer, String>();
public Election(Set<String> s, Map<Integer, String> m)
{ Set<String> stemp = s;
Map<Integer, String> mtemp = m;
int num = 1; String temp = "";
do
{ temp = mtemp.get(1);
ArrayList<Integer> del = new ArrayList<Integer>();
for(int poop : mtemp.keySet())
{ if(temp.equals(mtemp.get(poop)))
{ num++;
del.add(poop);
}
}
for(int poop = 0; poop < del.size(); poop++)
mtemp.remove(poop);
totals.put(num, temp);
}while(!mtemp.isEmpty());
System.out.println("kkkk"+totals.toString());
}
}[/PHP]
ok, the problem that i ran into is at [PHP]if(temp.equals(mtemp.get(poop)))[/PHP] i'm getting a nullPointerException. i dont get y this is happening. can someone help me?
the map m is:
{1=AbBaCdDc, 2=CdBaDcAb, 3=BaDcCdAb, 4=CdBaAbDc, 5=CdBaAbDc, 6=CdBaDcAb, 7=AbBaCdDc, 8=CdBaAbDc, 9=AbBaCdDc, 10=AbBaCdDc, 11=CdBaDcAb, 12=AbBaCdDc}
and the set s is:
[Ab, Dc, Cd, Ba]
[PHP]/*Election*/
import java.util.*;
public class Election
{ private Map<Integer, String> totals = new HashMap<Integer, String>();
public Election(Set<String> s, Map<Integer, String> m)
{ Set<String> stemp = s;
Map<Integer, String> mtemp = m;
int num = 1; String temp = "";
do
{ temp = mtemp.get(1);
ArrayList<Integer> del = new ArrayList<Integer>();
for(int poop : mtemp.keySet())
{ if(temp.equals(mtemp.get(poop)))
{ num++;
del.add(poop);
}
}
for(int poop = 0; poop < del.size(); poop++)
mtemp.remove(poop);
totals.put(num, temp);
}while(!mtemp.isEmpty());
System.out.println("kkkk"+totals.toString());
}
}[/PHP]
ok, the problem that i ran into is at [PHP]if(temp.equals(mtemp.get(poop)))[/PHP] i'm getting a nullPointerException. i dont get y this is happening. can someone help me?
the map m is:
{1=AbBaCdDc, 2=CdBaDcAb, 3=BaDcCdAb, 4=CdBaAbDc, 5=CdBaAbDc, 6=CdBaDcAb, 7=AbBaCdDc, 8=CdBaAbDc, 9=AbBaCdDc, 10=AbBaCdDc, 11=CdBaDcAb, 12=AbBaCdDc}
and the set s is:
[Ab, Dc, Cd, Ba]
0
Comments
On a side note, I would recommend much much more descriptive names (and comments) so it is easier for someone else to read your code.