将枚举类型添加到列表中 [英] Adding enum type to a list

查看:132
本文介绍了将枚举类型添加到列表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我需要在列表中添加枚举属性,那么我如何声明列表。让我们说枚举类是:

If I need to add an enum attribute to a list, how do I declare the list. Let us say the enum class is:

public enum Country{ USA,CANADA;}

我需要做:

List<String> l = new ArrayList<String>();
l.add(Country.USA);

需要使用什么而不是列表< String>?? c $ c>

What needs to be used instead of List<String>?

推荐答案

如果您想要使用字符串类型:

If you want the string type use this:

l.add(Country.USA.name());

否则MByD的答案

这篇关于将枚举类型添加到列表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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