Saturday, June 2, 2018

How to Compare List Objects in Java 7 vs. Java 8

Comparing the content of Lists against some condition is a common use case to handle in many business scenarios. This comparison can be broadly classified as:

  1. Comparing each element of a List against some condition. As an example, you have a List of Employee Objects and you need to check that all your Employees are above 18.
  2. One or more elements from one List match(es) the elements of another List.
  3. All elements of a List exist in another List.

Now, developing these use cases is very easy in Java 7 with relatively few lines of code. The following is an example where we are comparing two Lists in Java 7 and checking if any element from List 1 exists in List 2.



from DZone.com Feed https://ift.tt/2kFn3AQ

No comments:

Post a Comment