What does EnumSet really mean?

后端 未结 10 1522
小蘑菇
小蘑菇 2020-12-04 16:08

I have the following example:

import java.util.EnumSet;
import java.util.Iterator;

public class SizeSet {

    public static void main(String[] args) {
             


        
10条回答
  •  被撕碎了的回忆
    2020-12-04 16:50

    Given the following example:

    ....
    public static final String S = "s";
    public static final String M = "m";
    public static final String L = "l";
    ....
    
    Set sizeSet = new HashSet();
    sizeSet.add(S);
    sizeSet.add(M);
    

    so, what is sizeSet in the above example?

    EnumSet is nothing different from the above example, only that EnumSet is a special Set implementation that works with and optimized with enum types, that's all.

提交回复
热议问题