Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 39796

How to iterate hashmap with highest String key value

$
0
0

HashMap<string, string=""> mapp=new HashMap<string, string="">(); mapp.put("ab","blue"); mapp.put("abc","black"); mapp.put("abcef","black"); mapp.put("abcd","pink"); for (Iterator it = alltyp.iterator(); it.hasNext();) { String finalstring = (String) it.next();

                          Iterator it1=mapp.entrySet().iterator();
                          while(it1.hasNext())
                          {
                              Map.Entry pairs = (Map.Entry) it1.next();
                              String key_ = (String) pairs.getKey();
                              String value_ = (String) pairs.getValue();
                              finalstring = finalstring.replaceAll(key_, value_);

                          }

                      }

I want to iterate with max key value means key value "abcdef" should iterate first then "abcd" then "abc". so that my replaceall function should replace highest value first.


Viewing all articles
Browse latest Browse all 39796

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>