java - replace array value with hashmap values -
hashmap<string, string> apos = new hashmap<string, string>(); apos.put("i'm","i am"); apos.put("can't","cannot"); apos.put("couldn't","could not"); string[] st = new string[]{"i'm","johny"}; iterator itr = apos.entryset().iterator(); (int = 0; < st.length; i++) { while((itr).hasnext()) { if (itr.equals(st[i])) { st[i].replace(st[i],??????(value of matched key)) } } }
i want compare string hashmap , rerplace word hashmap value if matches key. above trying do. please me should write in place of key.
help appreciated. thanks
you don't need iterate on map find out whether array value key in map. use
map#containskey()
method that. so, rid of iterator.if (map.containskey(s[i]))
you don't need replace @ all. can assign new value array index using
=
operator.s[i] = newvalue;
to value map particular key set in array, use
map#get(object)
method.map.get(s[i]);
Comments
Post a Comment