• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

removeAll List is not working

 
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to keep only strings that are in one list but not the other :



Here my code :



but it looks like the list allAgenciesList still the same after removeAll.

Thanks.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Looks like? You can tell for sure because the removeAll method returns a boolean value which is true if the list was changed in any way.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

majid nakit wrote:Here my code :...


Majid,

Please DontWriteLongLines. It makes your thread very hard to read. I've broken yours up this time, but please read the link before you post any more code.

Thanks

Winston
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

majid nakit wrote:Here my code...


Just as a matter of interest, what's that 'vToolsDelegate' object? Is it some Gson/Json widget? If so, I'm darn glad I don't have to use it.

I start seeing double if I have more than 3 or 4 parameters to deal with; but 13? That's insane...

Winston
 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Speaking of insane... those class and variable names are horrific. The Hungarian Notation warts you have there may be typical of C programs but I would think that even Simonyi would cringe at how his notation is used here.
 
Junilu Lacar
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you have more than three parameters consider refactoring to use a Builder instead.
 
Junilu Lacar
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This code works:

Check your actual list contents, you may not actually have what you think you have. Also, I don't understand why you have to make your lists have these concatenated values. Why not just use the ids or names if they're going to be the same anyway? Then when you've excluded the items that you want to exclude, then you can build out your "name==id" strings. Seems like you're doing a lot of things before you actually need to do them. Also, removeAll will use the equals() method of the list items to determine whether they need to be removed or not. Instead of doing string concatenations, why don't you just use a proper domain object with an equals implementation?
 
Junilu Lacar
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is the output when I run the code I just gave:

$ java TestRemoveAll
mainList changed = true
[TestAppServer Agency==2547, DWN test agency for multi-agent ica agent==3562, test agency for multi-agency ica agent==3560, Acceptance Test Agency==510, SAI agency created for soaptesting==2587, Agency for ICA testing==3558, GIC test agency for multi-agent ica agent==3561, SOW TEST Agency==3498]

Size of mainList before is 12, Size mainList after is 8.
reply
    Bookmark Topic Watch Topic
  • New Topic