我有这个方法应该检查一个键是否在地图中,然后增加一个值。
papers.add(paper); //add a paper to the paper collection
papersOrdered.get(papers); //returns the papers
if(!(papersOrdered.containsKey(paper))) {
paperNo = 1;
String noPaper = Integer.toString(paperNo); //convert the paperNo integer to a String
papersOrdered.put(papers,noPaper); //put the rooNo and the paper collection into the HashMap
System.out.println("'" + paper + "'" + " has been added to the paper order. " + noPaper + " copy ordered" ); //a message to say a paper has been added
}
else{
paperNo = paperNo ++;
String noPaper = Integer.toString(paperNo); //convert the paperNo integer to a String
papersOrdered.put(papers,noPaper); //put the rooNo and the paper collection into the HashMap
System.out.println("'" + paper + "'" + " has been added to the paper order." + noPaper + " copies ordered" ); //a message to say a paper has been added
}
System.out.println("======================================================="); ; //a line to seperate text
System.out.println(" "); //a blank line
但是它不起作用,我不知道为什么?