Skip to content

Instantly share code, notes, and snippets.

@pramodpk89
Created April 24, 2020 12:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pramodpk89/3c4bfcb22f00fb4222379c2221da0e36 to your computer and use it in GitHub Desktop.
Save pramodpk89/3c4bfcb22f00fb4222379c2221da0e36 to your computer and use it in GitHub Desktop.
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