我想獲得的HashMap存儲字符串和ArrayList<String>.
Basicly什麼,我想要的是第一個字符串是一個名稱,以及該ArrayList包含每個國家的用戶已到。的HashMap <字符串,ArrayList的<String>>
"The HashMap contains: {Andrew=[USA, China, Sweden, Denmark], Lola=[USA, China, Sweden, Denmark]}"
ArrayList<String> namelist = new ArrayList<>();
ArrayList<String> test = new ArrayList<>();
ArrayList<String> archive = new ArrayList<>();
HashMap<String, ArrayList<String>> thearchive = new HashMap<>();
(input.equals("New Country")){
System.out.println("Name of the Person? ");
String name = in.nextLine();
if(namelist.contains(name)){
System.out.println("Which Country have you visited?");
String country = in.nextLine();
if (archive.contains(country)){
System.out.println("You've already visited this country.");
}
else {
test.add(country);
thearchive.put(name, country);
System.out.println("HashMap Contains: " + thearchive);
}
}
else{
System.out.println("The person does not exist please add first.");
}
是否有人知道爲什麼HashMap中沒有存儲鍵/值對:
Example:
{Andrew, [USA, China]}
{Lola, [Sweden, Denmark]}
我遇到的問題是,每當用戶將在一個國家,這個國家將被這兩個名稱下存儲我也想要嗎?
您需要提供其餘的代碼。 – archie