Java arrayToMap(String[][] array) Utility Method - Convert Array to Map

This page contains the source code of the JavaarrayToMap(String[][] array) utility method - This method converts a 2-dimensional array into a map where the first dimension is 2 cell String array containing key and value respectively. Any array with fewer than 2 elements is ignored.

This utility method is very useful if you want to convert a 2-dimensional array into a Map.

Java arrayToMap(String[][] array) Utility Method

This method converts a 2-dimensional array into a map where the first dimension is 2 cell String array containing key and value respectively. Any array with fewer than 2 elements is ignored.
publicstaticMap<String,String> arrayToMap(String[][] array) {Map<String,String> map=newHashMap<String,String>();for (String[] pair: array) {if (pair.length>1) {// got a pair, add to map             map.put(pair[0], pair[1]);         }    }return map;}

Related Utility Methods


Comments