1

I have a json list as follows:

"edgelist":[{"value":15.0,"date":20130729,"type":"url","destination":"224883242"},
               {"value":15.0,"date":20130729,"type":"url","destination":"224883243"},
               {"value":15.0,"date":20130730,"type":"url","destination":"224883242"}
             ]

Take a look at "destination and date..

Destination 224883242 is repeated twice..

What I want to keep is just latest unique jsons ... So the output would be

"edgelist":[               {"value":15.0,"date":20130729,"type":"url","destination":"224883243"},
                   {"value":15.0,"date":20130730,"type":"url","destination":"224883242"}
                 ]

What is the best way to do this...?

If destination and date are same.. keep either but not both.

1 Answer 1

2
  1. Model these JSON objects as proper Java objects. Give them a Class.

  2. Implement hashcode and equals for that Class so that they depend on the destination and date fields.

  3. Push all your objects into a Set. The resulting collection will have no duplicates.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.