bad solution:
<code>
import java.util.Hashtable;
public class InnerNotStatic {
static String keys[];
static String names[];
static Hashtable makeHash(String start) {
class myHash extends Hashtable {
public myHash() {
super(10);
}
public void buildHash(String str) {
for (int i=0; i<keys.length; i++) {
if( names[i].startsWith( str )) {
put ( keys[i], names[i]);
}
}
}
}
myHash h = new myHash();
h.buildHash( start );
return h;
}
public static void main(String[] args) {
InnerNotStatic inner = new InnerNotStatic();
keys = new String[] {"k1","k2","k3","k4","k5"};
names = new String[] {"starting", "startup", "nothing", "toy", "boy"};
Hashtable hashtable = new Hashtable(10);
for(int i=0; i<keys.length; i++) {
hashtable.put(keys[i], names[i]);
}
System.out.println(hashtable.toString());
Hashtable hashTemp = new Hashtable(10);
hashTemp = makeHash("start");
System.out.println(hashTemp.toString());
}
}
</code>
I made the variables and method as static.
A good solution would be to provide accessor and mutator methods for keys and names of the InnerNotStatic class. By the way, your InnerNotStatic is not a Inner Class?? or may be I didnt understand your question!