JAVA Map

 

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class text2 {

	public static void main(String[] args) {
		
		Map map = new HashMap();
		
		map.put("String", "这是一个字符串");
		map.put("Object", new Object());
		map.put("int", 1234);
		map.put(1, 1);
		map.put(new Object(), new Object());
		map.put(null , null);
		
		
		Set set = map.keySet();
		Iterator it = set.iterator();
		while(it.hasNext()){
			System.out.println(it.next());
		}
	}
}

如果换为TreeMap,那么后三种put无法实现,插入key不能为整形(没有写Compete方法,强制转换错误),没有实现Object接口,二叉树不允许null,

相关文章:

  • 2022-12-23
  • 2021-08-07
  • 2022-01-02
  • 2021-12-31
  • 2022-01-24
  • 2021-10-25
猜你喜欢
  • 2021-11-16
  • 2021-04-30
  • 2021-05-05
  • 2021-11-04
  • 2021-08-10
相关资源
相似解决方案