請參見使用HashMap的以下類定義。HashMap方法/參數
爲什麼沒有必要像第二種方法那樣將方法的形式參數傳遞給局部參數?
import java.util.HashMap;
public class MapTester
{
private HashMap<String, String> phoneBook = new HashMap<String, String>();
public MapTester()
{
phoneBook.put("Homer Jay Simpson", "(531) 9392 4587");
phoneBook.put("Charles Montgomery Burns", "(531) 5432 1945");
phoneBook.put("Apu Nahasapeemapetilon", "(531) 4234 4418");
}
public void enterNumber(String name, String number)
{
phoneBook.put(name, number);
}
public String lookupNumber(String _name)
{
name = _name;
return phoneBook.get(name);
}
}
是的,並感謝您的提示:) 乾杯! – Pato