You might want to try CollectionUtils.filter() using a Predicate. On Sun, May 13, 2012 at 7:02 AM, Ludwig Magnusson <[email protected]> wrote: > Hello! > I have two lists and I want to use the methods ListUtils.retainAll and > ListUtils.removeAll on them. However, I want to do this several times with > comparison methods that are different from the defaul equals-method. I.e I > would like to compare the elements in the two lists from several different > prespectives. > > Consider a class Person that has the attributes firstName and lastName. I > could define the equals method to say that two persons equals if they have > the same first name. I could also say that they equals if they have the same > full name. But what if I want to alternate? > > So basically what I want to do is this: > List<Person> firstList; > List<Person> secondList; > List<Person> firstNamesThatOccurInBothLists = ListUtils.retainAll(firstList, > secondList, [Third equals-comparator argument]); > List<Person> fullNamesThatOccurInBothLists = ListUtils.retainAll(firstList, > secondList, [Third equals-comparator argument]); > > Can something of this effect be done with commons collections in any way? > /Ludwig
--------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
