package snippets.collecectionApis; import java.util.HashMap; public class Maps { public static void main(String[] args) { // {key:value, key2:value2 ...} // France: Paris // Italy: Rome // Norway: Oslo // US: Washington DC HashMap<String, String> countryCapitals = new HashMap<>(); countryCapitals.put("France","Paris"); countryCapitals.put("Italy", "Rome"); countryCapitals.put("Norway", "Oslo"); countryCapitals.put("US", "Washington DC"); System.out.println( countryCapitals.get("Italy")); } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter