JAVA 字典作为参数

现在我有一本这样的字典


Dictionary dict = new Hashtable();

dict.put("shipno", item.getShipNumber());

dict.put("addr", item.getFinalAddr());

dict.put("receiver", item.getReceiverName());

dict.put("phone", item.getReceiverPhone());

我将把这个字典传递给funcion Test()作为参数,我应该在'()'中放些什么


public static int Test(Dictionary)

这是正确的吗?谢谢!


LEATH
浏览 168回答 2
2回答

哈士奇WWW

在代码中,您必须调用此方法:Dictionary dict = new Hashtable();dict.put("shipno", item.getShipNumber());// CAll THIS METHODTest(dict);在您的方法中,您可以获得以下数据:// YOUR METHOD, where "dict" is passed argument/parameterpublic static int Test(Dictionary dict) {}

墨色风雨

它在这里工作import java.util.Dictionary;import java.util.Enumeration;import java.util.Hashtable;public class Dict {public static void main(String[] args) {&nbsp; &nbsp; Dictionary<String, String> obj = new Hashtable<String, String>();&nbsp; &nbsp; obj.put("Hello", "World");&nbsp; &nbsp; obj.put("Hello1", "World3");&nbsp; &nbsp; obj.put("Hello2", "World32");&nbsp; &nbsp; Dict ca = new Dict();&nbsp; &nbsp; ca.test(obj);}public void test(Dictionary<String, String> obj) {&nbsp; &nbsp; Enumeration<String> enumData = obj.elements();&nbsp; &nbsp; while (enumData.hasMoreElements()) {&nbsp; &nbsp; &nbsp; &nbsp; System.out.println(enumData.nextElement());&nbsp; &nbsp; }&nbsp; }}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java