I need to sum the value in same key not just to replace? Thanks.
LinkedHashMap<String, LinkedHashMap<String, Integer>> users = new LinkedHashMap<>();
for (int i = 0; i < n; i++) {
String[] input = scanner.readLine().split("\\s+");
String ip = input[0];
String name = input[1];
int duration = Integer.parseInt(input[2]);
if (!users.containsKey(name)) {
users.put(name, new LinkedHashMap<>());
users.get(name).put(ip,duration);
} else {
users.get(name).put(ip,duration);
}
}
addDuration(int duration)method to the class to add a duration to the cumulated duration. Java is an OO language. Use classes. This will make your code much clearer (and faster, too).