从 TreeMap [keySet()] 获取键向量

Get Vector of keys from TreeMap [keySet()]

我正在 CacheBean 中创建树结构,如下所示:

private TreeMap<String,Object> locations = new TreeMap<String,Object>();

所以一位数据看起来像这样:

ThisKey=[Chris,Jim,Rick,David]

我想让用户从键列表中选择。但是,如果我将 TreeMap 直接绑定到该字段,则会出现此错误:

javax.faces.FacesException: java.util.TreeMap incompatible with java.util.List

如何获取键向量以用作选择列表?我试过使用

CacheBean.treeMap.keySet();

但这不起作用。

如果你想要一个Vector它是

Vector<String> v = new Vector<>(CacheBean.treeMap.keySet());

编辑

但正如 Java API documentation 所述:

As of the Java 2 platform v1.2, this class was retrofitted to implement the List interface, making it a member of the Java Collections Framework. Unlike the new collection implementations, Vector is synchronized. If a thread-safe implementation is not needed, it is recommended to use ArrayList in place of Vector.

您可能应该使用 ArrayList,它的工作原理与几乎任何 Java Collection class.

一样