封裝角色權限管理類 RoleRight,使用 Hashtable 存儲角色→權限代碼映射,實現初始化、查詢、新增、刪除、修改、列印全套操作,並示範 Enumeration 遍歷鍵值。
public class RoleRight {
private static Hashtable rightList = new Hashtable();
public void init() {
String[] roles = {"admin","satrap","manager","user","guest"};
String[] codes = {"10001","10011","10021","20011","24011"};
for (int i=0;i
Hashtable 同步安全、不允許 null 鍵值,適合多執行緒環境。Enumeration 僅支援單向遍歷:hasMoreElements() + nextElement()。ConcurrentHashMap + Iterator/forEach,效能與 API 更優。