• Post Reply Bookmark Topic Watch Topic
  • New Topic

Updating ArrayList<Object> and removing duplicates  RSS feed

 
Anthony Johnson
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm working with Apachi POI. During the main code I collect the stockCode and the quantities. At this part of the code it writes everything to my worksheet. How do I updated the quantity of the stockCodes exp. 0032029507 should have a quantity of (2). Also after I update the quantity, I want to remove the duplicates.

Any suggestions.



  • Worksheet Item List
    1 0000015643
    1 0032029507
    4 0000005670
    16 0000005685
    2 0000003796
    30 0000000426
    6 0000000171
    3 0000011909
    2 0000015789
    5 0000004375
    2 000124-425
    3 0032103543
    2 0000014861
    2 0000000359
    4 0000012908
    3 0000016149
    5 0000000362
    1 0000015623
    2 0000000151
    4 0000000450
    1 0000015644
    1 0032029507
    4 0000005670
    16 0000005685
    2 0000003796
    30 0000000426
    6 0000000171
    3 0000011909
    2 0000015789
    5 0000004375
    2 000124-425
    3 0032103543
    2 0000014861
    2 0000000359
    4 0000012908
    3 0000016149
    5 0000000362
    1 0000015623
    2 0000000151
    4 0000000450
  •  
    Anthony Johnson
    Ranch Hand
    Posts: 45
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Also I had that should be j++. I was working on another way and removed it.
     
    Adam Chalkley
    Ranch Hand
    Posts: 518
    4
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    create a method that checks for duplicates(implement a find method and return null or -1 if the object does not exist)

    or you could just use a HashMap or even HashSet instead
     
    Anthony Johnson
    Ranch Hand
    Posts: 45
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I figured it out. See below.

     
    Knute Snortum
    Sheriff
    Posts: 4288
    127
    Chrome Eclipse IDE Java Postgres Database VI Editor
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Anthony, thanks for posting your solution.  I've got a couple of questions and suggestions for you.

    * See comment below

    -------------------------------------------------------------

    * This can be simplified to

    ----------------------------------------------------------------
    * See comment below


     
    Anthony Johnson
    Ranch Hand
    Posts: 45
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Knute Snortum wrote:Anthony, thanks for posting your solution.  I've got a couple of questions and suggestions for you.

    * See comment below

    -------------------------------------------------------------

    * This can be simplified to

    ----------------------------------------------------------------
    * See comment below




    For your suggestion I really appreciate it. In a lot of my old comments, I announce that I'm getting back to using Java, or coding in general. That is a trick that I forgot about.

    For question two, yes there can be multiple. Which way you think would be faster.

    As for your first question, I'm not sure, I will try my best to run it through debug and let you know which I get a chance to work on it.
     
    Knute Snortum
    Sheriff
    Posts: 4288
    127
    Chrome Eclipse IDE Java Postgres Database VI Editor
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Anthony Johnson wrote:For question two, yes there can be multiple. Which way you think would be faster.

    It's not a matter of faster, it's a matter of completeness.  With the break you could miss duplicates.  Simply remove the break.
    As for your first question, I'm not sure, I will try my best to run it through debug and let you know which I get a chance to work on it.

    I'm pretty sure you will get an ArrayIndexOutOfBoundsException.
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!