我有这样的输入
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]]
我确实喜欢这个..
但我没有得到相同的输出。我的输出正在重复。
你能帮我吗...
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);
}