如何在不重新排序的情况下从列表中删除重复项?

dev*_*l08 2 java collections linked-list linkedhashset

我试图从使用Set Interface的String类型的List对象中删除重复项,但我遇到的问题是它也重新排序我的列表,这是我不想要的.我想保留列表的顺序并仅删除重复项?

static List<String>  StopNames = new ArrayList<String>();

StopNames.add(sCurrentLine);

Set<String> set = new HashSet<String>(StopNames);


for (String string : set) {

 System.out.println("Printing Set "+string);

}
Run Code Online (Sandbox Code Playgroud)

Lou*_*man 7

只需切换HashSetLinkedHashSet,它保留插入顺序,同时除去重复项.