package lt.bit.zodziai; import java.io.File; import java.io.FileNotFoundException; import java.util.HashSet; import java.util.Scanner; import java.util.Set; import java.util.TreeSet; public class Vykdymas { private static void readText(Set words, String fileName) throws FileNotFoundException { Scanner in=new Scanner(new File(fileName)); while(in.hasNext()){ String tmp=(in.next()).toLowerCase(); tmp=tmp.replace(".",""); tmp=tmp.replace(",",""); tmp=tmp.replace(":",""); words.add(tmp); } in.close(); } public static void main(String[] args) throws FileNotFoundException { Set s=new TreeSet<>(); readText(s,"tekstas1.txt"); readText(s,"tekstas2.txt"); System.out.println(s+"\n\n"); //---------------------------------------------- Set f1=new TreeSet<>(); readText(f1,"tekstas1.txt"); Set f2=new TreeSet<>(); readText(f2,"tekstas2.txt"); Set rezultatas=new TreeSet<>(); for(String tmp:f1){ if (f2.contains(tmp)){ rezultatas.add(tmp); } } System.out.println("Atsikartojantys: "+rezultatas); /* Set s=new TreeSet<>(); s.add(new Darbuotojas("Jonas")); s.add(new Darbuotojas("Petras")); s.add(new Darbuotojas("Jonas")); System.out.println(s.size()); System.out.println(s); */ } }