I have 2 arraylists contained objects like this:
1st arraylist contains string and double : [a 1.1, b 1.2, d 0.4, g 1.9, f 0.5 and so on…]
2nd arraylist contains string, double and int : [b 0.1 2, f 1.1 5, g 2.3 1, a 1.1 2 and so on…]
2nd arraylist may contain either same or greater or lesser number of items in it than 1st one but all its string property values will be any of those which are only present in 1st one’s string property.
All I need to sort the 2nd arraylist by the string property according to the order of 1st arraylist string property. 1st arraylist is already in order and if I sort the 2nd one then the expected output will be:
[a 1.1 2, b 0.1 2, g 2.3 1, f 1.1 5 …..]
I’ve seen some questions and answers with comparator but all of them are doing sort with one type of arraylist. But here I have 2 types of arraylist and I really don’t know how to do it!
So if you have any idea please share it with me and if possible share some sample code.
I am a novice in stackoverflow as well as have not much experience in Java. I’m having a great trouble with this situation. After googling and searching particularly in stackoverflow but couldn’t get any helpful idea to go through. I’ve explained the situation above and please pardon me if I made any mistake!
Thanks!
Lets assume the object in
list1andlist2are of type Foo and Bar and they both implement a methodgetString()which returns the string property. Like you said, the string values in list 1 are unique.