package myPro1; import java.util.HashMap; import java.util.Map; import java.util.Set; //The use of the Map interface and the implementation class HashMap //The difference between Map interface and Set and List is that it does not inherit the collection interface public class T6 { public static void main(String[] args) { Map<Integer, String> map = new HashMap<Integer, String>(); // store key-value pairs map.put(1, "dick"); map.put(2, "rick"); map.put(3, "nick"); String str = map.get(2);// Get data System.out.println(str); //traverse Set<Integer> keys = map.keySet();//Get all keys for (Integer key : keys) { String str2 = map.get(key); System.out.println(key + ":" + str2); } } }
Use of Map interface and implementation class HashMap
Guess you like
Origin http://10.200.1.11:23101/article/api/json?id=327042551&siteId=291194637
Ranking