Well, at first I thought it would be pretty simple. But I can’t come up with an effective way to solve this problem. I decided that this can be done, but it is not very elegant. I have an ArrayList. Contacts is a VO class that has several members - name, regions, identifier. There are duplicates in ArrayList because different regions appear several times. The list is sorted by identifier. Here is an example:
Intro 0 - Name: John Smith; Region: N; ID: 1 | Record 1 - Name: John Smith; Region: MW; ID: 1 | Record 2 - Name: John Smith; Region: S; ID: 1 | Record 3 - Name: Jane Doe; Region: NULL; ID: 2 | Record 4 - Name: Jack Black; Region: N; ID: 3 | Record 6 - Name: Jack Black; Region: MW; ID: 3 | Record 7 - Name: Joe Don; Region: NE; ID: 4
I want to convert the list below by combining repeating areas together for a single ID. Therefore, in the final list there should be only 4 separate elements with combined regions.
Thus, the result should look like this: -
Intro 0 - Name: John Smith; Region: N, MW, S; ID: 1 | Record 1 - Name: Jane Doe; Region: NULL; ID: 2 | Record 2 - Name: Jack Black; Region: N, MW; ID: 3 | Record 3 - Name: Joe Don; Region: NE; ID: 4
What are your thoughts on the best way to solve this problem? I am not looking for actual code, but ideas or tips to find the best way to do this.
Thank you for your time!!!
source
share