Is the following use of synchronized correct?
I know that the code below doesn't need to use synchronized because it doesn't run on a different thread, I just want to know if it's correct to use.
import java.util.*;
class HelloWorld {
private static Map<String, String> map = new HashMap<>();
public static void main(String[] args) {
synchronized (all())
{
for(String str : all())
{
//Some Stuff
}
}
}
public static Collection<String> all()
{
return map.values();
}
}