I know HashMaps are not sorted in any way. Somehow the Task wants the output to be in the same order as the input. Maybe you can help me achieve this. I have no clue how to sort a Map by the sequence of the input.
package de.codegym.task.task10.task1019;
import java.io.*;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
/*
Funktionalität ist nicht genug!
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
HashMap<String, Integer> map = new HashMap<>();
boolean check = true;
while (check){
try {
int id = Integer.parseInt(reader.readLine());
String name = reader.readLine();
map.put(name,id);
}catch (Exception e){
check = false;
}
/*if (id == null || name.equals("")){
check = false;
}else{
map.put(id,name);
}*/
}
for (Map.Entry<String, Integer> entry : map.entrySet()) {
System.out.println(entry.getKey() + " " + entry.getValue().toString());
}
}
}