[英]Batching in Java and Excel gives different results
I need to batch elements that have similar client id (String type, but at the moment only numeric values, like "12345", "235134", etc.) 我需要批处理具有相似客户端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);
}
The problem is that when I compare this function with the results of Excel ( =SUM(IF(FREQUENCY(C2:C618,C2:C618)>0,1))
), then I get different results, ie 526 and 519. 问题是,当我将此函数与Excel的结果进行比较( =SUM(IF(FREQUENCY(C2:C618,C2:C618)>0,1))
)时,会得到不同的结果,即526和519。
Is something wrong with my code? 我的代码有问题吗?
Your problem is here: 您的问题在这里:
String id = c.getIdClient();
List<Client> _clients = _batched.get(id);
if(_clients == null){
pois = new ArrayList<Client>();
_batched.put(id, _clients);
}
_clients.add(c);
You create a new array into a variable called pois
but then put the contents of the variable _clients
into _batched
. 您在名为pois
的变量中创建了一个新数组,然后将变量_clients
的内容放入_batched
。 What happens with the value put into pois
? pois
的价值发生了什么?
I don't understand how that doesn't null pointer exception actually. 我不明白这实际上不会为空指针异常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.