集册 Java实例教程 创建类型

创建类型

欢马劈雪     最近更新时间:2020-01-02 10:19:05

361
创建特定于类型的映射[5.0]

import java.net.MalformedURLException;

import java.net.URL;

import java.util.HashMap;

import java.util.Map;// 来自 时 代 J a v a - N o w J a v a . c o m


public class Main {

  public static void main(String[] argv) throws Exception {

    Map<Integer, String> map = new HashMap<Integer, String>();


    map.put(1, "first");

    map.put(2, "second");

    // map.put(1, 2); <- Syntax error

    Map<Number, String> numMap = new HashMap<Number, String>();


    numMap.put(.5, "half");

    numMap.put(1, "first");

    map.put(null, null);

    Map<String, URL> urlMap = new HashMap<String, URL>();

    try {

      urlMap.put("java", new URL(
展开阅读全文