類似的項目我有這樣分組使用HashMap的
0 [0.327097, 0.326998, 0.0]
0 [1.056364, 0.601873, 0.0]
0 [1.273154, 1.656441, 0.0]
1 [1.48469, 0.095074, 0.0]
1 [1.061504, -0.768175, 1.0]
一個輸入,我需要給他們排序爲
0 : [ [0.327097, 0.326998, 0.0] ,[1.056364, 0.601873, 0.0], [1.273154, 1.656441, 0.0]]
1 : [ [1.48469, 0.095074, 0.0], [1.061504, -0.768175, 1.0]]
我不喜歡這個..
,但我沒有得到相同的output.my輸出重複。
u能請幫助我......
Map<String, Collection<String>> groupMap = new HashMap<String, Collection<String>>();
String[] subparts = finalline.split("\\[");
String groupKey;
String value;
if (subparts.length == 1) {
groupKey = null;
value = subparts[0];
}
else if (subparts.length == 2) {
groupKey = subparts[0];
value = subparts[1];
}
else {
throw new IllegalArgumentException("Can not parse string");
}
Collection<String> groupContents = groupMap.get(groupKey);
if (groupContents == null) {
groupMap.put(groupKey, groupContents = new ArrayList<String>());
}
groupContents.add(value);
}