在我的场景中,hashTable就像这样
AId=1
BId=1
catalogId=10053
reason_1=RET-KP
reason_2=RET-KP
quantity_1=1.0
ItemId_1=468504
quantity_2=1.0
ItemId_2=468505
现在我需要在_i
时删除所有reason_i=RET-KP
件事
即。 delete ItemId_1 & quantity_1
reason_i
为reason_1
,reason_2
那么我如何迭代这个hashTable并根据它们的值删除键(动态)并再次将它存储在hashTable中。
答案 0 :(得分:0)
检查这将解决您的问题。
package com.loknath.lab;
public class HashTableDemo {
public static void main(String args[]) {
Hashtable htable = new Hashtable(3);
boolean deleteStatus;
ArrayList<String> list = new ArrayList<String>();
// populate the table
htable.put("AId", 1);
htable.put(" catalogId", 2);
htable.put(" ItemId_1", 43);
htable.put("ItemId_2", 43);
htable.put("bid", 54.45);
Set<String> keys = htable.keySet();
for (String key : keys) {
System.out.println(key);
deleteStatus = check(key);
if (deleteStatus) {
list.add(key);
}
}
for (String string : list) {
htable.remove(string);
}
}
public static boolean check(String key) {
boolean status = false;
status = key.contains("_");
return status;
}
}