HashMap返回空值

Pan*_*ari -3 java hashmap

嘿伙计这是我的代码在循环中我把mapTable.get("NN").它给出了正确的值,但是在循环外的print语句中它给出了null.请帮助.

Map<String,String> mapTable=new HashMap<String,String>();
    while((line2=br1.readLine())!=null)
    {
        if((!line2.trim().isEmpty())&&Character.isDigit(line2.charAt(0)))
        {
        String[] tmp=line2.split("\t");
        mapTable.put(tmp[1].trim(),tmp[2].trim());
        System.out.println("MAP-----"+tmp[1]+ " ->  "+tmp[2]+" ex "+mapTable.get("NN"));
        }   
    }
    printMap(mapTable);
    System.out.println("CHECKING-------> "+mapTable.get("NN"));


This is the output:

MAP-----NN  ->  n ex n
MAP-----NNS  ->  n ex n
MAP-----NNP  ->  n ex n
MAP-----NNPS  ->  n ex n
MAP-----PDT  ->   ex n
and so on..
JJ = adj
NN = n
WRB = adv
LS = 
PRP = prp
DT = dt
FW = pw

CHECKING-------> null
Run Code Online (Sandbox Code Playgroud)

PrintMap功能:

    public static void printMap(Map mp) {
    Iterator it = mp.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry pair = (Map.Entry)it.next();
        System.out.println(pair.getKey() + " = " + pair.getValue());
        it.remove(); // avoids a ConcurrentModificationException
    }
}
Run Code Online (Sandbox Code Playgroud)

Mat*_*oka 5

删除行:

it.remove(); // avoids a ConcurrentModificationException
Run Code Online (Sandbox Code Playgroud)

在此行中,您将从地图中删除所有元素.