A thread safe method to delete nodes from a Linkedlist.
public void delete(String x, LinkedList<String> list)
{
String lock = "false";
for (int i = 0; i < list.size(); i++) {
synchronized (lock) {
if (list.get(i).equals(x)) {
lock = "true";
list.remove(i);
}
lock = "false";
}
}
}
Many thanks!
Edit: the above method is thread safe but its performance needs to improve. It is an interview question.