Machine-translated by Google. Questions are authored in English.
Top

Discussion

Which of these correctly declares a thread-safe list?

  • A.synchronized List<String> l = new ArrayList<String>();
  • B.List<String> l = Collections.synchronizedList(new ArrayList<String>());
  • C.List<String> l = new SynchronizedList<String>();
  • D.List<String> l = new ArrayList<String>().synchronized();

Answer: B

Collections provides static wrapper methods that return a synchronized view of an existing collection. There is no SynchronizedList class to instantiate, no synchronized method on a collection, and the keyword cannot be applied to a variable.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.