나는 자바에 익숙하지 않고 지금 학습하고있다. 아래의 프로그램을 해시 테이블에 키 값 쌍을 저장하려고 시도했다. 키와 값을 추가하고 검색 할 수 있습니다.아래의 hashTable 프로그램이 작동하지 않습니까?
public static void main(String[] args){
Hashtable balance= new Hashtable();
Enumeration names;
String str;
int a;
balance.put("vishnu",new Integer(1000));
balance.put("Sam",new Integer(1420));
balance.put("Gobi",new Integer(890));
balance.put("Vel",new Integer(50));
names=balance.keys();
while(names.hasMoreElements()){
str=(String) names.nextElement();
System.out.println(str + " is getting "+balance.get(str));
}
System.out.println();
하지만 추가 된 값을 수정하려고 시도했습니다. 이것은 나에게 널 포인터 예외를 준다.
a=((Integer) balance.get("vel")).intValue();
System.out.println("Before Adding "+a);
balance.put("Vel", new Integer(a+1000));
System.out.println("After adding "+balance.get("vel"));
}