I have 2 array lists which contains a custom object Stock.
public class Stock{
private String companyName;
private double stockPrice;
// getters and setters
}
List1 contains Stock objects . List2 also contains stock objects.
List 1 and list 2 are same in size. There are some stock objects in list 1 which are same as present in list 2. I need to get those same objects which re present in list 1 out of list 2. i.e. in another words get the intersection of list 1 and list 2 in list 2. I am trying to find out if there is any direct way in Java 8 which gives this result in an efficient way .Or if not , how to construct an efficient algorithm in terms of time complexity and space complexity ? Help is highly appreciated.