I'm struck with my project... have to maintain large hashmap of lang arrays.... i try this with sample but its not working.... I cant store keys in arrays.... thanks in advance...
class K{
int key;
}
class V{
int data;
}
class hashmp{
public static void main(String args[]){
HashMap<K,V> hm=new HashMap<K,V>();
K key1=new K();
for(int i=0;i<5;i++){
V val=new V();
key1.key=i;
val.data=i+5;
hm.put(key1,val);
}
System.out.println();
for(int i=0;i<5;i++){
key1.key=i;
V pt=hm.get(key1);
System.out.println("\n"+hm.containsKey(key1)+key1.key);
if(hm.containsKey(key1))
System.out.print(pt.data);
}
}
}
for that i'm getting....
true0
9
true1
9
true2
9
true3
9
true4
9
updated code.....
class K{
long key;
}
class V{
long[] v=new long[10];
}
public void putHash(V val1){
//some code
V s=new V();
K gt=new K();
gt.key=val1.v[0];
if(hm.containsKey(keyArr[(int)gt.key])){
s=hm.get(gt); //get value of key if exists
//some code to modify s
}
gt.key=val1.v[0];
hm.put(gt,s); // put the modified value back to same key
}
Thank you all to provide me the answers... finally it works well... Thanks for everyone's contribution....