我有UIMA对象,其中包含许多带annotatios的文件
我正在迭代这个对象并将内容保存在arraylist
中Iterator Iter = UIMA.iterator();
while (Iter.hasNext())
{
FirstName fn = (FirstName) Iter.next();
String name=fn.getName();//It will return the name
vc.add(name); //Adding to arraylist
System.out.println(name);
}
return vc;
这里的问题是如果我打印出名字。所有预期的名字都打印出来 但该向量包含重复项,如下所示
For firstfile
name1 name2 name3
For second file
name1 name2 name3 name12 name22 name23
For 3rd file
name1 name2 name3 name12 name22 name23 name31 name32 name33
为什么这些元素会多次添加?
答案 0 :(得分:2)
Iterator Iter = UIMA.iterator();
vc = new ArrayList(); // HERE is where you need to create your vc object
while (Iter.hasNext())
{
FirstName fn = (FirstName) Iter.next();
String name=fn.getName();//It will return the name
vc.add(name);
System.out.println(name);
}
return vc;