Java – Converts hadoop’s Configuration to MapString, String

Converts hadoop’s Configuration to Map… here is a solution to the problem.

Converts hadoop’s Configuration to Map

How do I convert hadoop’s Configuration conf to Map<String, String>?

I

have a method that takes Map as a parameter and I want to pass Configuration conf to it, so how do I convert between the two?

Solution

You can use Configuration provides an iterator and builds the map.

Configuration configuration = new Configuration();
Map<String, String> map = new HashMap<>();
Iterator<Map.Entry<String,String>> iterator = configuration.iterator();
while (iterator.hasNext()) {
  Map.Entry<String, String> entry = iterator.next();
  map.put(entry.getKey(), entry.getValue());
}

You can also look at This method, which takes a regular expression and returns the configured Map <>.

Related Problems and Solutions