【发布时间】:2012-11-28 05:14:52
【问题描述】:
我写了以下java代码:
public static void main(String[] args) {
Vector vector = new Vector();
for(int i=1; i<=10; i++)
vector.addElement(i);
Enumeration vEnum = vector.elements();
while(vEnum.hasMoreElements())
System.out.println(vEnum.nextElement());
}
编译时收到以下警告消息:
Note: TestJavaApplication.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Netbeans 抱怨“过时的集合”消息。
在这种情况下,您有什么建议?
注意,我需要在 J2ME 应用程序中使用 Vector 作为存储元素顺序的动态数组。我很乐意使用 Hashtable,但不幸的是它不存储元素的顺序。
编辑 1
在查看了this answer 之后,我将声明从Vector vector = new Vector(); 更改为Vector<String> vector = new Vector<String>();。现在收到另一条警告消息:
TestJavaApplication.java:2: warning: com.sun.org.apache.xerces.internal.parsers.IntegratedParserConfiguration is Sun proprietary API and may be removed in a future release
import com.sun.org.apache.xerces.internal.parsers.IntegratedParserConfiguration;
^
谢谢。
【问题讨论】:
-
你在网上搜到错误信息了吗?
-
在 J2ME 中可以使用 TreeMap 吗?我认为不是。