我的取值從地圖來像下面如何根據某些特定值對地圖中的值進行分組?
Key = 1_1, Value = 02/04/2012
Key = 1_2, Value = 03/04/2012
Key = 1_3, Value = 04/04/2012
Key = 1_4, Value = 05/04/2012
Key = 1_5, Value = 06/04/2012
Key = 1_6, Value = 09/04/2012
Key = 1_7, Value = 10/04/2012
Key = 1_8, Value = 11/04/2012
Key = 1_9, Value = 12/04/2012
Key = 1_10, Value = 13/04/2012
Key = 1_11, Value = 18/04/2012
Key = 1_12, Value = 19/04/2012
Key = 1_13, Value = 20/04/2012
Key = 1_14, Value = 23/04/2012
Key = 1_15, Value = 24/04/2012
Key = 1_16, Value = 25/04/2012
Key = 1_17, Value = 26/04/2012
Key = 1_18, Value = 27/04/2012
Key = 1_19, Value = 30/04/2012
Key = 10_20, Value = 02/04/2012
Key = 10_21, Value = 03/04/2012
Key = 10_22, Value = 04/04/2012
Key = 10_23, Value = 05/04/2012
Key = 10_24, Value = 06/04/2012
Key = 10_25, Value = 09/04/2012
Key = 10_26, Value = 10/04/2012
Key = 10_27, Value = 11/04/2012
Key = 10_28, Value = 12/04/2012
Key = 10_29, Value = 13/04/2012
Key = 10_30, Value = 16/04/2012
Key = 10_31, Value = 17/04/2012
Key = 10_32, Value = 18/04/2012
Key = 10_33, Value = 19/04/2012
Key = 10_34, Value = 23/04/2012
Key = 10_35, Value = 24/04/2012
Key = 10_36, Value = 26/04/2012
Key = 10_37, Value = 27/04/2012
我真的很努力分開這些值,並把它們放在單獨的地圖。
我想分組如下。
1_1到1_19這個我想根據「_」進行分割並單獨獲得第一個值並將它們分組到一個單獨的地圖中。
像1是關鍵,值將是日期。
編輯:
employeeMap = showExelData(sheetData);
String previousEemployeeID = "",employeeID[];
Iterator<Map.Entry> entries = employeeMap.entrySet().iterator();
while (entries.hasNext()) {
Map.Entry entry = entries.next();
employeeID = entry.getKey().toString().split("_");
// this is the place where i want to check the values if 1 than group the values it can be even Key = 1_0, Value = 25/04/2012 to If Key = 1_18, Value = 30/04/2012
but when the other one comes ex : Key = 10_0, Value = 25/04/2012 to If Key = 10_17, Value = 30/04/2012it has to go to new Map
我這是在哪裏欠缺的地方。 }
'HashMap's要求'key'是唯一的。有19個等於'1'的鍵不能用於HashMap。 – npinti
你是相當不確定的,你的意思是「將它們分組在一張單獨的地圖中」。你想要一個'Map>'這樣'outer.get(「1」)。get(「3」)。equals(「04/04/2012」)'?或者你更喜歡一個'Map >',每個鍵只有幾個值。 –
@nd感謝評論,我有幾個值如上所述,我想將這些值在單獨的地圖,因爲它是,但一個地圖將有整個值設置爲例如:1_1到1_19和第二張地圖將有10_1到10_x同樣我想分組他們。 – SAR