Java 向堆栈对象的哈希表添加元素

Java 向堆栈对象的哈希表添加元素,java,stack,hashtable,Java,Stack,Hashtable,我有一个HashTable的Stack对象: Hashtable<String, Stack<Integer>> ht; “foo”和“bar”是键,两个[x,y,z]是堆栈 如何使用键“a”将一个整数推送到哈希表中的堆栈上 非常感谢。你试过了吗 yourHashTable.get("a").push(new Integer(2)); 你试过了吗 yourHashTable.get("a").push(new Integer(2)); 您可以尝试以下方法: if(h

我有一个
HashTable
Stack
对象:

Hashtable<String, Stack<Integer>> ht;
“foo”
“bar”
是键,两个
[x,y,z]
是堆栈

如何使用键
“a”
将一个
整数推送到哈希表中的堆栈上

非常感谢。

你试过了吗

yourHashTable.get("a").push(new Integer(2));
你试过了吗

yourHashTable.get("a").push(new Integer(2));

您可以尝试以下方法:

if(ht.containsKey("a")) {
  ht.get("a").push(0); // push some Integer
}
else {
  Stack<Integer> stack = new Stack<Integer>();
  stack.push(0); // push some integer
  ht.put("a",stack);
}
if(ht.containsKey(“a”)){
ht.get(“a”).push(0);//推一些整数
}
否则{
堆栈=新堆栈();
stack.push(0);//推一些整数
ht.put(“a”,堆栈);
}
你需要使用

p.S:如果可以,移动到而不是
哈希表


阅读

您可以尝试以下方法:

if(ht.containsKey("a")) {
  ht.get("a").push(0); // push some Integer
}
else {
  Stack<Integer> stack = new Stack<Integer>();
  stack.push(0); // push some integer
  ht.put("a",stack);
}
if(ht.containsKey(“a”)){
ht.get(“a”).push(0);//推一些整数
}
否则{
堆栈=新堆栈();
stack.push(0);//推一些整数
ht.put(“a”,堆栈);
}
你需要使用

p.S:如果可以,移动到而不是
哈希表


读取

以修改给定堆栈,检索对该堆栈的引用并添加新整数

myHashTable.get("a").push(new Integer(7));

为了修改给定的堆栈,检索对它的引用并添加新的整数

myHashTable.get("a").push(new Integer(7));
Stack-Stack=hashtable.get(键);
stack.push(myint);
hashtable.put(键、堆栈);
类似这样的东西,可能:)?

Stack=hashtable.get(key);
stack.push(myint);
hashtable.put(键、堆栈);

类似这样的东西,也许:)?

ht.get(“a”).push(myInteger),但如果您自己在代码中尝试过,它会更好。。也许我该关门了。。这太明显了,不利于其他人?!非常感谢.ht.get(“a”).push(myInteger),但如果您自己在代码中尝试过这一点会更好。。也许我该关门了。。这太明显了,不利于其他人?!非常感谢。