publicclasstest1{staticFileaFile=newFile("Source");staticStringaString=null;publicstaticvoidmain(String[]args)throwsIOException{BufferedReaderaReader=newBufferedReader(ne...
public class test1 {
static File aFile = new File("Source");
static String aString = null;
public static void main(String[] args) throws IOException {
BufferedReader aReader = new BufferedReader(new InputStreamReader(new FileInputStream("Source")));
while ((aString = aReader.readLine()) != null) {
String [] aArray = aString.split(":");
HashMap aMap = new HashMap();
for(int i=0;i
String key = aArray[2*i];
if(aMap.containsKey(key)){
aMap.put(key,aMap.get(key)+Integer.parseInt(aArray[2*i+1]));
}else{
aMap.put(key,Integer.parseInt(aArray[2*i+1]));
}
System.out.println(aMap.entrySet());
}
}
aReader.close();
}
}
source 文件类似于:
A:34
B:23
C:33
D:23
A:4
E:5
问题是为什么:这些相同的键能写进map中 aMap.containsKey(key)不被执行----------------请求大侠帮忙 ,小弟超级大菜鸟
展开