if(callingflag)
{
int calledUserTp = totalPointsByUserid(callinguserid,jokercard);
System.out.println("Total Points of the User Who has made a Call is ::"+calledUserTp);
HashMap<Integer,Integer> useridTotalRankMap = totalPointsforEveryUser(jokercard);
HashMap<Integer,Integer> useridTotalRankMapSorted = new HashMap<Integer, Integer>();
useridTotalRankMapSorted = (HashMap<Integer, Integer>) sortByComparator(useridTotalRankMap);
for(Map.Entry<Integer, Integer> entry :useridTotalRankMapSorted.entrySet())
{
System.out.println( entry.getKey() +"----"+entry.getValue());
if(entry.getKey() == callinguserid )
{
System.out.println( "GOOD CALL");
break;
}
}
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能避免上面提到的for循环.useridTotalRankMapSorted是一个Map
我有这个名为useridTotalRankMap的hashmap,它将具有一些总点数的用户ID.
我想检查对应于calleruserid的值是否是该hashmap中的最小值,前提是没有关系.
说是
1:4
4:7
3:7
2:5
Run Code Online (Sandbox Code Playgroud)
和calleruserid = 1.如果key = 1的值(即4)是最小值,则打印"good call".
希望我现在很清楚.
我编码的方式有什么变化吗?