我想按以下格式打印我的字符串。 ua, login, login ---> ua, navigation, fault Average = 500 milliseconds
。我將這兩個字符串存儲到一個名爲keyString
的字符串中,並將其放入由"|"
分隔的hashmap中。然後我分裂,當我迭代鍵集來獲取它的格式,我原來的陳述,但它是這樣顯示---> ua, ctiq, export|ua, ctiq export, transfer Average = 600 milliseconds
。有任何想法嗎?打印拆分字符串
public static void ProcessLines(Map<String, NumberHolder> uaCount,String firstLine, String secondLine) throws ParseException
{
String [] arr1 = firstLine.split("-- ", 2);
String [] arr2 = secondLine.split("-- ", 2);
String str1 = arr1[1];
String str2 = arr2[1];
......
String keyString = str1 + "|" + str2;
NumberHolder hashValue = uaCount.get(keyString);
if(hashValue == null)
{
hashValue = new NumberHolder();
uaCount.put(keyString, hashValue);
}
hashValue.sumtime_in_milliseconds += diffMilliSeconds;
hashValue.occurences++;
public static class NumberHolder
{
public int occurences;
public int sumtime_in_milliseconds;
}
和繼承人部分
for(String str : uaCount.keySet())
{
String [] arr = str.split("|",2);
long average = uaCount.get(str).sumtime_in_milliseconds/uaCount.get(str).occurences;
//System.out.println(str);
System.out.println(arr[0] + " ---> " + arr[1] + " Average = " + average + " milliseconds");
}
對不起,我沒有把代碼放在第一個請不要downvote – user2007843
爲什麼這麼多downvotes? – Pshemo
@Pshemo - 可能是因爲一開始沒有代碼。獲得的經驗:發佈您的問題與您的問題。 – LittleBobbyTables