Mega Code Archive

 
Categories / Java Tutorial / Collections
 

A value retrieved from a type-specific collection does not need to be casted

import java.net.MalformedURLException; import java.net.URL; import java.util.HashMap; import java.util.Map; public class Main {   public static void main(String[] argv) {     Map<String, URL> urlMap = new HashMap<String, URL>();     try {       urlMap.put("java", new URL("http://www.rntsoft.com"));     } catch (MalformedURLException e) {     }     String s = urlMap.get("java").getHost();   } }