Requirement -
I have a list of objects as given below -
[
TestObj{levelCode='123', operId='ABC', hrchyInd='S'},
TestObj{levelCode='456', operId='DEF', hrchyInd='S'},
TestObj{levelCode='123', operId='ABC', hrchyInd='M'}
]
My desired output is -
[
TestObj{levelCode='123', operId='ABC', hrchyInd='B'},
TestObj{levelCode='456', operId='DEF', hrchyInd='S'},
]
If two TestObj in the list are having the same levelCode && OperId but different hrchyInd then we should include only one TestObj out of the two in the output list and modify the hrchyInd as B.
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.ToString;
@Data
@AllArgsConstructor
@ToString
@Builder
public class TestObj {
private String levelCode;
private String operId;
private String hrchyInd;
}
Can anyone please help me to solve this problem in an optimal way.