天天看点

随手记:Map.ketSet()

对同一个map取keySet()得到的结果相同,用equals和==得到的都是true

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package map;

import java.util.LinkedHashMap;
import java.util.Set;

/**
 *对同一个map取keySet()得到的结果相同,用equals和==得到的都是true
 * @author Jq
 */
public class MapTestMain {
    
    private void mapTest() {
	LinkedHashMap<Integer, String> testMap = new LinkedHashMap<>();
	testMap.put(1, "one");
	testMap.put(2, "two");
	testMap.put(3, "three");
	Set keySet_1 = testMap.keySet();
	Set keySet_2 = testMap.keySet();
	System.out.println("Equals:" + keySet_1.equals(keySet_2));
	System.out.println("==: " + (keySet_1 == keySet_2));
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
	MapTestMain test = new MapTestMain();
	test.mapTest();
    }
    
}