如何获取枚举的子集 [英] How to fetch a subset of an enumeration

查看:137
本文介绍了如何获取枚举的子集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大多数情况下,包含所有元素的枚举都显示在用户界面的下拉列表中。我们需要在用户界面中仅显示5个字段中的2个。通过某种方式利用可用于枚举的相同函数,获取此数据的更简单方法是什么。

Most of the times an enumeration containing all elements is shown in a drop down in the user interface. We have a need to show only 2 out of 5 fields in the user interface. What would be an easier way to fetch this data, by somehow leveraging the same functions available for an enumeration.

enum Color {RED, GREEN, BLACK, BLUE, YELLOW};

我们要求在某个用户界面中只显示{RED,BLUE}?

We have a requirement to show only {RED, BLUE} in a certain user interface?

推荐答案

听起来像 EnumSet

EnumSet<Color> set = EnumSet.of(Color.RED, Color.BLUE);

这篇关于如何获取枚举的子集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆