Java中将Array转换成map类型的方法

上大王 分享于 3小时前 2758阅 0人收藏此代码, 我要收藏

Java中将Array转换成map类型的方法

import java.util.Map;
import org.apache.commons.lang.ArrayUtils;
 
public class Main {
 // http://www.sharejs.com/codes/
  public static void main(String[] args) {
    String[][] countries = { { "United States", "New York" }, { "United Kingdom", "London" },
        { "Netherland", "Amsterdam" }, { "Japan", "Tokyo" }, { "France", "Paris" } };
 
    Map countryCapitals = ArrayUtils.toMap(countries);
 
    System.out.println("Capital of Japan is " + countryCapitals.get("Japan"));
    System.out.println("Capital of France is " + countryCapitals.get("France"));
  }
}
//该代码片段来自于: http://www.sharejs.com/codes/java/8844

标签:
  • Array
  • map
  • 类型转换