Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.util.HashSet;
- import java.util.Scanner;
- import java.io.FileNotFoundException;
- public class ZadanieDwaPliki {
- public static void main(String[] args) throws FileNotFoundException {
- // TODO Auto-generated method stub
- Scanner skan1 = new Scanner(new File("plik1.txt"));
- Scanner skan2 = new Scanner(new File("plik2.txt"));
- HashSet<String> tab1 = new HashSet<String>();
- HashSet<String> tab2 = new HashSet<String>();
- while (skan1.hasNextLine()) {
- tab1.add(skan1.nextLine());
- }
- while (skan2.hasNextLine()) {
- tab2.add(skan2.nextLine());
- }
- HashSet<String> wspolne = new HashSet<String>(tab1);
- wspolne.retainAll(tab2);
- System.out.println("Wspólne " + wspolne);
- HashSet<String> roznica = new HashSet<String>(tab1);
- roznica.removeAll(tab2);
- System.out.println("Różnica " + roznica);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment