-
-
Save pramodpk89/3c4bfcb22f00fb4222379c2221da0e36 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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