-1

I have two objects with many parameters. I need to compare it by each field and put information about what field is different

How to do it clean?

I'm not happy with something like that

if(<condition>) {
    list.add(object.getParam());
}
if(<condition>) {
    list.add(object.getParam());
}
if(<condition>) {
    list.add(object.getParam());
}
if(<condition>) {
    list.add(object.getParam());
}
(...)
   

Maybe there is cleaner way to do it by stream for example?

sajgon338
  • 11
  • 7

1 Answers1

0
switch (a) {
    case condition1:
        list.add(val);
        break;
    case condition2:case condition3:
        list.add(val);
        break;
    default:
        break;
}

so, you mean this.

4b0
  • 21,981
  • 30
  • 95
  • 142
varuscn
  • 131
  • 2
  • 2
  • It's good practice on StackOverflow to add an explanation as to why your solution should work. – 4b0 Oct 30 '20 at 10:46