0

Now I got a dictionary like this

Dictionary dict = new Hashtable();
dict.put("shipno", item.getShipNumber());
dict.put("addr", item.getFinalAddr());
dict.put("receiver", item.getReceiverName());
dict.put("phone", item.getReceiverPhone());

and I'm going to pass this dictionary to funcion Test() as a parameter, what should I put in the '()'

public static int Test(Dictionary)

Is this correct? Thanks!

許家瑄
  • 97
  • 4

2 Answers2

1

In your code you have to call this method:

Dictionary dict = new Hashtable();
dict.put("shipno", item.getShipNumber());

// CAll THIS METHOD
Test(dict);

And in your method you can get this data:

// YOUR METHOD, where "dict" is passed argument/parameter
public static int Test(Dictionary dict) {

}
Boken
  • 4,825
  • 10
  • 32
  • 42
0

Its working here

import java.util.Dictionary;
import java.util.Enumeration;
import java.util.Hashtable;

public class Dict {

public static void main(String[] args) {

    Dictionary<String, String> obj = new Hashtable<String, String>();
    obj.put("Hello", "World");
    obj.put("Hello1", "World3");
    obj.put("Hello2", "World32");
    Dict ca = new Dict();
    ca.test(obj);
}

public void test(Dictionary<String, String> obj) {
    Enumeration<String> enumData = obj.elements();
    while (enumData.hasMoreElements()) {
        System.out.println(enumData.nextElement());
    }
  }
}
Ankit
  • 307
  • 1
  • 8