Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
package com.ppkcodes;
import java.util.Arrays;
import java.util.List;
import java.util.function.BiConsumer;
public class BiConsumerAndThenExample {
public static void main(String[] args) {
BiConsumer<List<String>, List<String>> compareList = (list1, list2) -> {
if (list1.size() == list2.size()) {
for (int i = 0; i < list1.size(); i++) {
if (!list1.get(i).equalsIgnoreCase(list2.get(i))) {
System.out.println("Both lists are not equal");
return;
}
}
System.out.println("Both lists are equal");
} else {
System.out.println("Both lists are not equal");
return;
}
};
BiConsumer<List<String>, List<String>> display = (list1, list2) -> {
System.out.println("List1 : ");
list1.stream().forEach(str -> System.out.println(" " + str));
System.out.println("=====================================");
System.out.println("List2 : ");
list2.stream().forEach(str -> System.out.println(" " + str));
};
List<String> names1 = Arrays.asList("Sachin", "Lara", "Waugh", "Gavaskar");
List<String> names2 = Arrays.asList("Sachin", "Lara", "Waugh", "Gavaskar");
compareList.andThen(display).accept(names1, names2);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.