我正在写一个代码来显示时间与大小。 我正在使用散列表制作条目。问题是,它正确地进行了计算,但最终当我尝试打印出散列表时,它不会显示7分钟内的所有结果。相反,它会显示last进入7个times.I已经尝试了很多弄清楚这个问题,但couldn't.Plzz帮我出HashMap打印只是最后一项
这里是我的代码
public class Analysis
{
public static class KeepTime
{
String time;
long TotalSize;
}
Main f1 = new Main();
public static int j = 0;
public static int check = 0;
public HashMap<String, KeepTime> hMap_time = new HashMap<String, KeepTime>();
public KeepTime TimerInstance = new KeepTime();
void TimeBasedReporting()
{
String skey;
String key;
int k;
int y;
for (k = 1; k <= f1.Flows().size(); k++)
{
check = 0;
j = 0;
skey = Integer.toString(k);
if (hMap_time.isEmpty())
{
//some code
key = Integer.toString(hMap_time.size() + 1);
hMap_time.put(key, TimerInstance);
j = 1;
}
else if (check == 0 && j == 0)
{
for (y = 1; y <= hMap_time.size(); y++)
{
//some code
}
}
}
if (check == 0 && j == 0)
{
// some code
key = Integer.toString(hMap_time.size() + 1);
hMap_time.put(key, TimerInstance);
}
else
{}
}
}
}
以下为输出
03:08:39,AM 424
03:08:39,AM 424
03:08:39,AM 424
03:08:39,AM 424
03:08:39,AM 424
03:08:39,AM 424
03:08:39,AM 424
03:08:39,AM 424
03:08:39,AM 424
03:08:39,AM 424
乍看之下,你似乎在滥用“地图”。它看起来像你真的想使用'List'。 – Bombe 2012-04-15 12:16:59
可能'hMap_time.size()'1 – 2012-04-15 12:18:11