我正在编写用于显示时间与大小的代码。我正在使用哈希图进行条目。问题是它正确地进行了计算,但最后当我尝试打印出哈希图时,它不会显示 7 分钟内的所有结果。而是显示最后输入的结果7 次。我已经尝试了很多来找出问题,但不能。请帮助我
这是我的代码
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