HashSet中包装类及其对应的基本类型重复数据问题

来源:互联网 发布:淘宝怎么设置上新提醒 编辑:程序博客网 时间:2024/06/15 22:45
/* * 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 test;import java.util.HashSet;import java.util.Set;/** * * @author huanghuankun */public class HashSetTest {    public static void main(String[] args) {        HashSet<Number> set = new HashSet<Number>();        byte num_byte = 1;        int num_int = 1;        Integer num_int1 = 1;        long num_long = 1;        set.add(num_byte);        set.add(num_int);        set.add(num_int1);//包装类和其对应的基本类型,在set中视为重复,不同类型hashcode不同        set.add(num_long);        System.out.println("set.sieze()=" + set.size());    }}

输出:

set.sieze()=3


0 0
原创粉丝点击