Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Collections;
- import java.util.LinkedHashSet;
- import java.util.Scanner;
- import java.util.Set;
- public class E02_SetOfElements {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int firstSize = scanner.nextInt();
- int secondSize = scanner.nextInt();
- scanner.nextLine();
- Set<String> nums = new LinkedHashSet<>();
- Set<String> nums2 = new LinkedHashSet<>();
- Set<String> repeated = new LinkedHashSet<>();
- for (int i = 0; i < firstSize; i++) {
- nums.add(scanner.nextLine());
- }
- for (int i = 0; i < secondSize; i++) {
- nums2.add(scanner.nextLine());
- }
- for (String num : nums) {
- if (nums2.contains(num)) {
- repeated.add(num);
- }
- }
- for (String num : repeated) {
- System.out.println(num + " ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement