-1

how can i compare below two lists, i need to compare each parameter of the queue as well, which ever queue is missing in the destList, i want it as output.

List<QueueInfo> sourceList;
    List<QueueInfo> destList; 

QueueInfo is a class

sourceList

[Queue['abcd',static,maxBytes=524288000,expiry=7200000],    Queue['def',static,maxBytes=524288000,expiry=7200000], Queue['xyz',static,maxBytes=524288000,expiry=7200000], Queue['wed',static,maxBytes=524288000,expiry=7200000]]

destList

[Queue['aaaaa',static,maxBytes=524288000,expiry=7200000], Queue['def',static,maxBytes=524288000,expiry=7200000], Queue['xcv',static,maxBytes=524288000,expiry=7200000], Queue['www',static,maxBytes=524288000,expiry=7200000]]

please suggest me any idea or how can I proceed. Thanks

Jalal
  • 77
  • 1
  • 2
  • 6

1 Answers1

0

I would create a class ComparableQueueInfo that extends the QueueInfo implementing the method equals properly.

Then you should create two lists of ComparableQueueInfo. Finally you can use the code:

sourceList.retainAll(destList)

to find all the ComparableQueueInfo objects in the sourceList that are contained on the destList.

If you want to find the ComparableQueueInfo objects in the sourceList that are missing on the destList you can use the method removeAll on the sourceList passing it a List of common objects built using the previuos retainAll method.

I hope that answer could resolve your problem

  • thanks for your suggestion. However, I tried using two for loops , each loop traversing the source and destList respectively and ,if the name matches on both lists, I removed that name from destList. with this logic i am able to find out the left out queues in destList :) – Jalal Apr 28 '15 at 19:02
  • for(int i=0;i – Jalal Apr 28 '15 at 19:08