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

Java String Utility Methods


This page contains the source code of 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.

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.

public static Map<String, String> arrayToMap(String[][] array) {
    Map<String, String> map = new HashMap<String, String>();

    for (String[] pair : array) {
         if (pair.length > 1) {
             // got a pair, add to map
             map.put(pair[0], pair[1]);
         }
    }
    return map;
}






Comments