简体   繁体   English

列表对象仅使用Java添加一个值

[英]List object adding only one value using java

I'm trying to add a lead id(string) to a list object.. Initially it iterates in a while loop, whichever lead id is null.. i'm adding that leadid to the list object.. after completing the iteration, that list object is handling only last leadid which got failed.. infact it should have other strings too. 我正在尝试将Lead ID(字符串)添加到列表对象。最初,它会在while循环中进行迭代,无论Lead ID为null。.我将LeadID添加到列表对象..完成迭代后,该列表对象仅处理最后一个失败的Leadid。实际上,它也应该具有其他字符串。

Here is my code . 这是我的代码。

 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);

The "list" object should have many lead ids which got failed. “列表”对象应具有许多失败的潜在顾客ID。

Any changes to be made? 有什么变化吗?

Thanks, 谢谢,

Your problem is that you create the list inside the loop, so the list only contains the last element you added. 您的问题是您在循环内创建了列表,因此列表仅包含您添加的最后一个元素。

Move this : 移动这个:

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

to be before the loop: 在循环之前:

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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Java中的堆栈将对象添加到数组列表中 - adding an object into an array list using stack in java 如何转换以创建一个新列表,使得列表中的每个 object 在嵌套列表中只有一个元素,每个元素都使用 Java? - How to transform to create a new List such that each object in list has only one element in the nested list each using Java? 使用 Java 8,如何为列表中的 obj[4] 设置字符串常量<Object[]>当且仅当它具有空值? - Using Java 8, How to set a String Constant for obj[4] in a List<Object[]> if and only if it has null value? 使用java 8划分对象列表中的bigdecimal值? - Divide the bigdecimal value in a list of object using java 8? 当 json 中的一个键包含值列表时,使用 Retrofit 将 JSON 键值对转换为 Java 对象 - Converting JSON key - value pair into Java object using Retrofit when one of the key in json contains a list of values TreeSet仅添加一个值? - TreeSet only adding one value? 在Java中将相同的对象添加到列表 - Adding the same object to List in Java 将 object 添加到 Java 中的数组列表中 - Adding object to an array list in Java Java:单链接列表,实例化4个唯一的SLList,但是将值添加到一个列表会向所有列表添加相同的值 - Java: Singly Linked List, instantiated 4 unique SLLists but adding a value to one list adds the same value to all lists 如何使用List设置对象值 <Object> 到java中的模型类? - How to set object value using List<Object> to a model class in java?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM