I am posting my query after having searched in this forum & google, but was unable to resolve the same.
eg: Link1 Link2 Link3
I am trying to filter List 2 (multi column) based on the values in List 1.
List1:
- [Datsun]
- [Volvo]
- [BMW]
- [Mercedes]
List2:
- [1-Jun-1995, Audi, 25.3, 500.4, 300]
- [7-Apr-1996, BMW, 35.3, 250.2, 500]
- [3-May-1996, Porsche, 45.3, 750.8, 200]
- [2-Nov-1998, Volvo, 75.3, 150.2, 100]
- [7-Dec-1999, BMW, 95.3, 850.2, 900]
expected o/p:
- [7-Apr-1996, BMW, 35.3, 250.2, 500]
- [2-Nov-1998, Volvo, 75.3, 150.2, 100]
- [7-Dec-1999, BMW, 95.3, 850.2, 900]
Code
// List 1 in above eg
List<dataCarName> listCarName = new ArrayList<>();
// List 2 in above eg
List<dataCar> listCar = new ArrayList<>();
// Values to the 2 lists are populated from excel
List<dataCar> listOutput = listCar.stream().filter(e -> e.getName().contains("BMW")).collect(Collectors.toList());
In the above code if I provide a specific value I can filter, but not sure how to check if Car Name in List 2 exits in List 1.
Hope the issue I face is clear, await guidance (Am still relatively new to Java, hence forgive if the above query is very basic).
Edit
I believe the link-3 provided above should resolve, but in my case it is not working. Maybe because the values in list-1 are populated as
org.gradle04.Main.Cars.dataCarName@4148db48 .. etc.
I am able to get the value in human readable format only when I do a forEach on List 1 by calling the getName method.
Question&Answers:
os