DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT <http://issues.apache.org/bugzilla/show_bug.cgi?id=30882>. ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND INSERTED IN THE BUG DATABASE.
http://issues.apache.org/bugzilla/show_bug.cgi?id=30882 [Collections - MapUtils]Method to generate a Map from a Object[][] Summary: [Collections - MapUtils]Method to generate a Map from a Object[][] Product: Commons Version: 1.6 Final Platform: Other OS/Version: Other Status: NEW Severity: Normal Priority: Other Component: Collections AssignedTo: [EMAIL PROTECTED] ReportedBy: [EMAIL PROTECTED] In Python Language it is possible create a dictionary (equivalent to Map) using only a single line: myMap = {'alpha':'a', 'betha':'b', 'gamma':'c'} In Java it is not possible. We must do it "manually": Map myMap = new HashMap(); myMap.put("alpha", "a"); myMap.put("betha", "b"); myMap.put("gamma", "c"); My propose is create a way to do this with less burocracy. In org.apache.commons.collections.MapUtils class could have a method called fillMap (or better name) that receives a Map and a bi-dimentional array of Objects. It will work like this: public static Map fillMap(Map map, Object[][] keyValue) { for(int i = 0; i < keyValue.length; i ++) { map.put(keyValue[i][0], keyValue[i][1]); } return map; } So, returning to prior example, we could do this: Map myMap = MapUtils.fillMap(new HashMap(), {{"alpha", "a"}, {"betha", "b"}, {"gama", "c"}}); Or to put in mass in a pre-existent MAP: MapUtils.fillMap(myMap, {{"delta", "d"}, {"epslon", "e"}, {"omega", "z"}}); --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
