Method to convert a ResourceBundle to a Map object.
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.ResourceBundle;
/**
* Utility class to convert one object to another.
*
* @author <a href="mailto:matt@raibledesigns.com">Matt Raible</a>
*/
public final class Util {
/**
* Method to convert a ResourceBundle to a Map object.
* @param rb a given resource bundle
* @return Map a populated map
*/
public static Map<String, String> convertBundleToMap(ResourceBundle rb) {
Map<String, String> map = new HashMap<String, String>();
Enumeration<String> keys = rb.getKeys();
while (keys.hasMoreElements()) {
String key = keys.nextElement();
map.put(key, rb.getString(key));
}
return map;
}
}
Related examples in the same category