【问题标题】:Batching in Java and Excel gives different resultsJava 和 Excel 中的批处理给出了不同的结果
【发布时间】:2013-12-16 10:54:42
【问题描述】:

我需要批处理具有相似客户端 ID 的元素(字符串类型,但目前只有数值,如“12345”、“235134”等)

Map<String, List<Client>> _batched = new HashMap<String, List<Client>>();
for (Client c : _Clients)
{
    String id = c.getIdClient();
    List<Client> clients = _batched.get(id);
    if(_clients == null){
        clients = new ArrayList<Client>();
        _batched.put(id, clients);
    }
    clients.add(c);
}

问题是,当我将此函数与 Excel (=SUM(IF(FREQUENCY(C2:C618,C2:C618)&gt;0,1))) 的结果进行比较时,我会得到不同的结果,即 526 和 519。

我的代码有问题吗?

【问题讨论】:

  • 不确定您是否只是在问题中输入了错误的代码,但您似乎在使用 _clientsclients 来引用 for 循环内的同一个列表。

标签: java list hashmap batch-processing


【解决方案1】:

你的问题在这里:

String id = c.getIdClient();
List<Client> _clients = _batched.get(id);
if(_clients == null){
    pois = new ArrayList<Client>();
    _batched.put(id, _clients);
}
_clients.add(c);

您在名为pois 的变量中创建一个新数组,然后将变量_clients 的内容放入_batched。放入 pois 的值会发生什么情况?

我不明白这实际上不是空指针异常。

【讨论】:

  • 谢谢。请参阅编辑后的帖子。对不起,这是我的打字错误。但问题还是一样。
  • 你从哪里得到最后的计数? (如何在 Java 中生成)
猜你喜欢
  • 2014-03-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-06
  • 2015-07-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多