Warnings: These examples are just examples. Not same my code, so don't think it's duplicate or it's bad question and vote down!
This title may be a little confusing sorry for that. Here's my problem;
I have two Arraylist. One of them takes a string and onether one takes integer. Let me illustrate it
arrList1 = {"apple", "strawberry", "banana", "watermelon"};
arrList2 = { 60, 90, 77 , 160};
arrList2 store how much fruits in arrList1 in same index number. For example there are 60 apples, 90 strawberry, 77 banana, 160 watermelon.
Also I have two more Arraylist like above;
arrList3 = { "strawberry", "watermelon", "apple", "banana" };
arrList4 = { 45, 40 , 10 , 11 };
arrList1 and arrList3 have same string but different index number. Now I want to print like by divide arrList2's number by arrList1 number and print objects by amount order. Let me illustrate it;
apple = 60/10 = 6
strawberry = 90/45 = 2
banana = 77/11 = 7
watermelon = 160/40 = 4
We divided and get some numbers and print to console ordered by amounts;
Banana // first because we got 7
Apple // second because we got 6 and etc
Watermelon
Strawberry
So, how I do it effectively?
To be clear, there are two questions here:
- How do I efficiently do the lookup for each fruit in each pair of arrays?
- How do I efficiently sort the results of dividing the corresponding entries' values?