The prints are correct, every requirement is met by the code I guess... So whats wrong?
package de.codegym.task.task17.task1701;
import java.util.ArrayList;
import java.util.List;
/*
Notizen
*/
public class Solution {
public static void main(String[] args) {
new NoteThread().start();
new NoteThread().start();
}
public static class NoteThread extends Thread{
public static final List<String> notes = new ArrayList<>();
public static void addNote(String note) {
notes.add(0, note);
}
public static void removeNote(String threadName) {
String note = notes.remove(0);
if (note == null) {
System.out.println("Ein anderer Thread hat unsere Notiz gelöscht");
} else if (!note.startsWith(threadName)) {
System.out.println("Thread [" + threadName + "] hat die Notiz eines anderen gelöscht [" + note + "]");
} else {
System.out.println("Thread [" + threadName + "] hat seine eigene Notiz gelöscht [" + note + "]");
}
}
public void run(){
for(int index = 0; index < 1000; index++) {
String s = getName() + "-Notiz" + index++;
addNote(s);
try {
Thread.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
removeNote(getName());
}
}
}
}