/
GermanezZ
/
JavaExercises
Обзор
Документация
Войти
/
GermanezZ
/
JavaExercises
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
AllMetanitLessons/Collections/Set/BookHashsets.java
48 строк
1 KB
germa
Уроки по Metanit
04 дек 2024, 20:39
04 дек 2024, 20:39
48d575a
Код
Авторство
О чём код?
package AllMetanitLessons.Collections.Set; import java.io.FileInputStream; import java.io.IOException; import java.util.*; public class BookHashsets { public static void main(String[] args) { Set<String> set1 = new HashSet<String>(); Collections.addAll(set1,"A B C D E F G H I J K L".split(" ")); set1.add("M"); System.out.println("-------------------------"); System.out.println(set1); System.out.println("-------------------------"); System.out.println("H: " + set1.contains("H")); System.out.println("N: " + set1.contains("N")); Set<String> set2 = new HashSet<String>(); Collections.addAll(set2,"H I J K L".split(" ")); System.out.println("set 2 in set1: " + set1.containsAll(set2)); System.out.println("-------------------------"); set1.remove("H"); System.out.println("set1: " + set1); System.out.println("---------------------------"); System.out.println("set2 in set 1: " + set1.containsAll(set2)); set1.removeAll(set2); System.out.println("set 2 removed from set1: " + set1); Collections.addAll(set1,"X Y Z".split(" ")); System.out.println("Z Y Z added to set1: " + set1); try(FileInputStream fin = new FileInputStream("D://Files//notes.txt")){ byte[] arr = new byte[fin.available()]; fin.read(arr); }catch (IOException exc){ System.out.println(exc.getMessage()); } } }