java枚举转集合_枚举集

java枚举转集合

In Java, EnumSet extends the AbstractSet and is implemented in the Set interface. This class is the member of the Java Collection Framework and also it can not be synchronized. EnumDet is faster than HashSet.

在Java中,EnumSet扩展了AbstractSet并在Set接口中实现。 此类是Java Collection Framework的成员,并且无法同步。 EnumDet比HashSet快。

Syntax:

句法:

public abstract class EnumSet>

下面是EnumSet类的方法 (Below are the methods of EnumSet Class)

S.no. Method Description
1 EnumSet of(E e1) It is used to create an Enum set using specified elements.
2 EnumSetcomplementOf(EnumSet s) It is used to create an Enum set using specified elements which are unique.
3 EnumSetallOf(Class elementType) It is used to create an Enum set using all the elements of the class.
4 EnumSet range(E from, E to) It is used to get the Enum elements of the given range.
5 EnumSetcopyof() It is used to copy the elements from the collection in a new enum set.
序号 方法 描述
1个 (E e1)的EnumSet 它用于使用指定的元素创建一个Enum集。
2 EnumSetcomplementOf(EnumSet s) 它用于使用唯一的指定元素创建一个Enum集。
3 EnumSetallOf(Class elementType) 它用于使用该类的所有元素创建一个Enum集。
4 EnumSet范围(E从,E到) 它用于获取给定范围的Enum元素。
5 EnumSetcopyof() 它用于在新的枚举集中复制集合中的元素。

Example:

例:

import java.util.EnumSet; 

enum Demo1
{ 
    RED, BLACK, BLUE, PINK, WHITE
}; 
public class EnumDemo1
{ 
    public static void main(String[] args)  
    { 
        EnumSet1 a1, a2, a3, a4; 
        a1 = EnumSet1.of(Demo1.RED, Demo1.BLACK, Demo1.BLUE, Demo1.PINK, Demo1.WHITE); 
        a2 = EnumSet1.complementOf(a1); 
        a3 = EnumSet1.allOf(Demo1.class); 
        a4 = EnumSet1.range(Demo1.RED, Demo1.PINK); 
		System.out.println("a 1: " + a1); 
		System.out.println("a 2: " + a2); 
		System.out.println("a 3: " + a3); 
		System.out.println("a 4: " + a4); 
    } 
}
java枚举转集合_枚举集_第1张图片

翻译自: https://www.studytonight.com/java/enum-set.php

java枚举转集合

你可能感兴趣的:(java枚举转集合_枚举集)