java中的hashmap key可以重复吗?
可以重复,但是重重以后的key会被覆盖
public static void main(String[] args)
{
System.out.println("dd World!");
Map<Integer, Integer> map = new HashMap<>();
int[] nums=new int[] {1,2,3,1};
for (int i = 0; i < nums.length; i++) {
map.put(nums[i], i);
}
System.out.println("dd World!");
}
但是c#中的hashtable ,dictionary key值是不能重复的。 会直接编译不通过
Dictionary<int, int> dic = new Dictionary<int, int>();
dic.Add(0, 0);
dic.Add(1, 1);
dic.Add(2, 2);
dic.Add(2, 2);
Console.WriteLine(111);
Console.ReadKey();
还不快抢沙发