Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package _7_SETS_AND_MAPS_ADVANCED.Exercise;
- import java.util.Arrays;
- import java.util.LinkedHashSet;
- import java.util.Scanner;
- import java.util.Set;
- public class _2_Sets_Of_Elements {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int[] nAndM = Arrays.stream(sc.nextLine().split("\\s+"))
- .mapToInt(Integer::parseInt).toArray();
- int nLength = nAndM[0];
- int mLength = nAndM[1];
- Set<Integer> n = new LinkedHashSet<>();
- Set<Integer> m = new LinkedHashSet<>();
- for (int i = 0; i < nLength; i++) {
- n.add(Integer.parseInt(sc.nextLine()));
- }
- Set<Integer> repeating = new LinkedHashSet<>();
- for (int i = 0; i < mLength; i++) {
- int newNumb = Integer.parseInt(sc.nextLine());
- m.add(newNumb);
- }
- n.forEach(e-> {
- if(m.contains(e)){
- repeating.add(e);
- }
- });
- repeating.forEach(e-> System.out.print(e+" "));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement