I have a problem to store data in this hashmap, I'm programming in Java.
My system consists of some chats, in the hash map I have to insert chats as indexes and the list of users who are connected to a specific chat, my problem is the initialization of the hashmap, as I only have to enter the chats but the arraylists are empty because there is no user connected, only I cannot understand how to do this correctly.
This is a little sample of my code:
public class Master {
private HashMap<String, ArrayList<String>> chatBox;
public Master() {
chatBox = new HashMap<String, ArrayList<String>>();
}
public insert() {
FileReader fr;
BufferedReader br;
try {
fr = new FileReader("listChat.txt");
br = new BufferedReader(fr);
while(true) {
String topic = br.readLine();
if(topic == null)
break;
chatBox.put(topic, null);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
new ArrayList<>().