【发布时间】:2014-02-20 03:10:43
【问题描述】:
我正在尝试使用 Set 接口从我的 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);
}
【问题讨论】:
-
使用 LinkedHashSet 代替
标签: java collections linked-list linkedhashset