gpt4 book ai didi

java - 使用java仅添加一个值的列表对象

转载 作者:太空宇宙 更新时间:2023-11-04 06:08:45 24 4
gpt4 key购买 nike

我正在尝试将一个引导 ID(字符串)添加到列表对象中。最初它在 while 循环中迭代,无论哪个引导 ID 为空。我将该引导 ID 添加到列表对象中。完成迭代后,该列表对象仅处理最后一个失败的引导 ID。事实上它也应该有其他字符串。

这是我的代码。

 while(iterLeadIds.hasNext()) {
String leadId = (String) iterLeadIds.next();
BankBridgeServiceRequest bankBridgeServiceRequest = new BankBridgeServiceRequest();
bankBridgeServiceRequest.setLeadId(leadId);
bankBridgeServiceRequest.setType(BankBridgeMethodType.webservice_Create_Lead);
LOG.info("Sending to web service Rev Lead ID = " + bankBridgeServiceRequest.getLeadId());
bankBridgeServiceResponse = bankBridgeService.run(bankBridgeServiceRequest);
String responseString = bankBridgeServiceResponse.getResponseString();
List<String> list = new ArrayList<String>();
if(responseString == null) {
bankBridgeUtilResponse.setStatus(false);
list.add(leadId);
bankBridgeUtilResponse.setFailedLeadIds(list);
LOG.info("webservice Rev got null response from Lead ID ::"+leadId);

“列表”对象应该有许多失败的潜在客户 ID。

有什么改变吗?

谢谢

最佳答案

您的问题是您在循环内创建列表,因此列表仅包含您添加的最后一个元素。

移动这个:

List<String> list = new ArrayList<String>();

在循环之前:

List<String> list = new ArrayList<String>();
while(iterLeadIds.hasNext()) {
String leadId = (String) iterLeadIds.next();
BankBridgeServiceRequest bankBridgeServiceRequest = new BankBridgeServiceRequest();
bankBridgeServiceRequest.setLeadId(leadId);
bankBridgeServiceRequest.setType(BankBridgeMethodType.webservice_Create_Lead);
LOG.info("Sending to web service Rev Lead ID = " + bankBridgeServiceRequest.getLeadId());
bankBridgeServiceResponse = bankBridgeService.run(bankBridgeServiceRequest);
String responseString = bankBridgeServiceResponse.getResponseString();
if(responseString == null) {
bankBridgeUtilResponse.setStatus(false);
list.add(leadId);
bankBridgeUtilResponse.setFailedLeadIds(list);
LOG.info("webservice Rev got null response from Lead ID ::"+leadId);

关于java - 使用java仅添加一个值的列表对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29006198/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com