Skip to content
Advertisement

how to combine two List<Map> [closed]

There are these two List<Map<String,Object>> in java

List<Map<String,Object>> voListResult = new ArrayList<Map<String,Object>>();

voListResult:

JavaScript

List<Map<String, Object>> productLikeRenew = likeDAO.SumProductLike();

productLikeRenew:

JavaScript

How can I update likecheck based on product_idx of both Lists in voListResult?

result:

JavaScript

I’ve been thinking about it for a few days, but it doesn’t work.

Advertisement

Answer

You can do the following things:-

  1. Sort both List of maps based on the product_idx number.
  2. define a counter for productLikeRenew and initialize with 0.
  3. Iterate voListResult list until product_idx of voListResult <= product_idx of productLikeRenew.
  4. If product_idx of both of them is equal then combine the result.
  5. Increment the counter.
  6. Repeat steps from 3 to 5 until one of the List is ended.
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement