Here I have some code(shortened to show the most important parts)
private Map<String, Color> hashMap = new HashMap<String, Color>();
for (int u = 0; u < people.size(); u++) {
    if (people.get(u) instanceof Boy) {
        list[u]="B";
        hashMap.put(list[u], Color.red);
        System.out.print("B");
    } else if (people.get(u) instanceof Girl) {
        System.out.print("G");
        list[e] = "G";
        hashMap.put(list[u], Color.green);
    }
}
public void paintComponent(Graphics g){
    super.paintComponent(g);
    g.drawString(list, 10, 10)
    // I would like to color each value according to its key in the hashMap list looping through my array
}
I would like my g.drawString() to loop through my array called list which contains [B,G,G,B,B,B,B,G] and color each value according to its colour based on my hashMap and return this array coloured..
so my hashMap["G" = color.green, "B"=color.red]
I tried this :
public void paint(Graphics g){
    g.setColor(hashMap.get("B") 
    g.setColor(hashMap.get("G")
    g.drawString(list, 10, 10)
}
but this seems to colour the whole text green or red could some one explain how to loop the the array called list and use g.drawString to colour each value accordingly?
EDIT
 for (int u = 0; u < people.size(); u++) { 
 Person p = people.get(u); 
list[u] = p.getGenderAsChar(); colorMap.put(r.getGenderAsChar(),r.getColorRepresentation() }
public void paintComponent(Graphics g){
super.paintComponent(g);
for (int c = 0; c< list.length; c++)
Person p = people.get(u);
 g.setColor(hashMap.getColorRepresentation);
g.drawString(list[c], 10 + c*10, 20);
}
 
     
    