I have an arraylist of objects which has a field "name" and I have a list of names. I have to select all the objects which consist of any of the name from the list. How can I achieve this in java most efficiently. Any code snippet will be highly appreciated.
Example:
Let the class name be A
A consists of fields such as id, name, subject etc.
So let's assume I have a list
List<A> objectsA
whose length let's say is 10. In this list, the name field consists of various names for eg alpha, beta, gama, delta etc etc.
So suppose I have a second list
List<String> namesList = List.of("alpha","beta");
So I want to select only those objects from objectsA list whose name fields consist of the names from namesList i.e. I want to select only those objects whose name fields consists of "alpha" or "beta".
List.ofis available since Java 9: docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/…