[java]代码库
package my.util;
import java.util.LinkedList;
import java.util.ListIterator;
/**
* 唯一字符串List
*/
public class UniqueStringList extends LinkedList<String> {
private boolean ignoreCase;
public UniqueStringList(boolean ignoreCase) {
this.ignoreCase = ignoreCase;
}
@Override
public boolean add(String e) {
ListIterator<String> iterator = listIterator();
while (iterator.hasNext()) {
String next = iterator.next();
if(ignoreCase?e.equalsIgnoreCase(next):e.equals(next))
return false;
}
return super.add(e);
}
public static void main(String[] args) {
UniqueStringList usl = new UniqueStringList(true);
usl.add("CodeSnippet.cn");
usl.add("codeSnippet.Cn");
usl.add("CODEsnippet.Cn");
for(String s : usl)
System.out.println(s);
}
}
//源代码片段来自云代码http://yuncode.net