Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package jc01_2020.avramkov.lesson10.task04;
- /*
- *
- * Заполнить карту записями вида "фамилия" - "имя". Вывести в консоль все пары значений. Удалить из карты все записи с
- * одинаковыми "именами" (если 2 и более человек имеют одинаковое имя, то удалить всех) и вывести в консоль оставшиеся записи.
- *
- */
- import org.w3c.dom.ls.LSOutput;
- import java.util.*;
- public class Application {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- Map<String, String> map = new TreeMap<>();
- /* for (int i = 0; i < 5; i++) {
- String surname = scanner.nextLine();
- String firstName = scanner.nextLine();
- map.put(surname,firstName);
- }*/
- /* HashMap<String, String> map = new HashMap<>();
- map.putAll(map1);*/
- map.put("A", "1");
- map.put("B", "2");
- map.put("C", "2");
- map.put("D", "3");
- map.put("E", "3");
- map.put("F", "4");
- map.put("G", "5");
- map.put("H", "6");
- map.put("Q", "3");
- map.put("R", "6");
- System.out.println("Начальный массив : " + map);
- System.out.println("------------------------------------------------------------");
- ArrayList<String> array = new ArrayList<>();
- for (Map.Entry<String, String> entry1 : map.entrySet()) {
- array.add(entry1.getValue());
- }
- System.out.println(array);
- array.remove("3");
- System.out.println(array);
- /* Iterator<Map.Entry<String, String>> iterator1 = map.entrySet().iterator();
- while (iterator1.hasNext()) {
- Map.Entry<String, String> entry = iterator1.next();
- System.out.println(entry.getKey() + " - " + entry.getValue());*/
- }
- }
- /*
- Map<String, String> map22 = new TreeMap<>();
- for (Map.Entry<String, String> entry1 : map.entrySet()) {
- for (Map.Entry<String, String> entry2 : map.entrySet()) {
- if (!entry1.getKey().equals(entry2.getKey()) && entry1.getValue().equals(entry2.getValue())) {
- map22.put(entry1.getKey(),entry1.getValue());
- }
- }
- }
- System.out.println("map22 : " + map22);*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement