0

Second question of the day :)

I have two ArrayLists containing data from two different Json APIs like:

coinList

coinList = new ArrayList<>();
priceLIst = new ArrayList<>();

    coinList: [{coin=Litecoin, confirmed=0.00}, {coin=Bitcoin, confirmed=0.00}, {coin=Zcoin, confirmed=0.00}]

priceList

priceList: [{coin=Bitcoin, price=1000}, {coin=Litecoin, price=1000}, {coin=Zcoin, price=1000}]

Is there a way to add the "price" for the second list to the first one where indexes coin match? Like, Bitcoin price to the Bitcoin in the first list and so on? The coins are in different orders in each list, but are formated the same. The idea would be to end up with a list like:

mergedList = new ArrayList<>();

    mergedList: [{coin=Litecoin, confirmed=0.00, price=1000}, {coin=Bitcoin, confirmed=0.00, price=1000}]

Obviously, the data in the lists is for ilustration purposes only :P The real lists contain a few more things for each coin in the first list, but, unless I'm much mistaken, that should not matter.

Hopefully this makes sense. I'm very new to this stuff, so any help would be appreciated, especially very noob friendly help! :)

Thanks!

Matt
  • 11
  • 4
  • 1
    https://stackoverflow.com/a/32850923/9025311 –  Apr 27 '18 at 15:59
  • for (Price price : priceList) { for (Coin coin : coinList) { if(price.getId().equals(coin.getCoin())) { coinPriceList.add(new CoinPrice(price.getId(), coin.getConfirmed(), price.getPrice())); } } } – Bhanuchandar Challa Apr 27 '18 at 16:14
  • @D.'s might be me, but that does not seem to work with ArrayList<>, or at least I can't get it to work. :( I did change the _priceList_ so that now, instead of **id** the key is **coin**, same as the _coinList_, but still not sure how to proceed. – Matt Apr 27 '18 at 16:28

0 Answers0