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

  1. 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])) 
  2. you don't need replace @ all. can assign new value array index using = operator.

    s[i] = newvalue; 
  3. to value map particular key set in array, use map#get(object) method.

    map.get(s[i]); 

Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

c++ - Clear the memory after returning a vector in a function -

erlang - Saving a digraph to mnesia is hindered because of its side-effects -