Java: Convertir un tableau à deux dimensions en un tableau associatif ‘Map’

Author:

 map, java, table
Download

 
import java.util.Map;
import java.util.HashMap;
 
public class ArrayToMap
 {
 
  public static void main(String[] args)
  	 {
    String[][] tab_pays = { { "Allemagne", "Berlin" }, { "Angleterre", "Londre" },
        { "Pays-Bas", "Amsterdam" }, { "Japon", "Tokyo" }, { "France", "Paris" } };
 
    Map map_pays = new HashMap();
    for(int x=0; x<tab_pays.length;x++)
    {
    	for(int i=0;i<tab_pays[x].length;i++)
    	{
    		map_pays.put(tab_pays[x][i],tab_pays[x][1]);
    	}
 
    }
 
    // Afficher une valeur du tableau associatif
    System.out.println (map_pays.get("France"));        // "paris"
  }
}

Cet article Java: Convertir un tableau à deux dimensions en un tableau associatif ‘Map’ est apparu en premier sur .