/*
 * 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


Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐