import java.util.*;
public class mhash
{
private Hashtable table;
public mhash()
{
table = new Hashtable();
}
public void put(double key, double value)
{
table.put(new Double(key), new Double(value));
}
public void put(String key, String value)
{
table.put(key, value);
}
public double get(double key)
{
Object ret = table.get(new Double(key));
if (ret instanceof Double)
return ((Double)ret).doubleValue();
else
return Double.NaN;
}
public String get(String key)
{
return (String)table.get(key);
}
}
data step中使用
data _null_;
length s $20;
/*
* Simple Java hash table test. mhash.class is a wrapper
* for java/util/Hashtable - so that we can pass Java strings
* directly instead of generic Objects.
*/
declare javaobj h("mhash");
/* Load up the table */
h.callVoidMethod("put", "key1", "data1");
h.callVoidMethod("put", "key2", "data2");
h.callVoidMethod("put", "key3", "data3");
h.callVoidMethod("put", "key4", "data4");
h.callVoidMethod("put", "key5", "data5");
/* Retrieve a value */
h.callStringMethod("get", "key3", s);
put s=;
run;
数组使用
data step数组能直接传到java对象中,如
import java.util.*;
import java.lang.*;
class jtest
{
public void dbl(double args[])
{
for(int i = 0; i < args.length; i++)
System.out.println(args[i]);
}
public void str(String args[])
{
for(int i = 0; i < args.length; i++)
System.out.println(args[i]);
}
}