Blog

Your dream job? Lets Git IT.
Interactive technical interview preparation platform designed for modern developers.

XGitHub

Platform

  • Categories

Resources

  • Blog
  • About the app
  • FAQ
  • Feedback

Legal

  • Privacy Policy
  • Terms of Service

© 2025 LetsGit.IT. All rights reserved.

LetsGit.IT/Categories/Java
Javahard

Why is `ArrayList` not thread-safe, and how can you make list access safe?

Tags
#concurrency#arraylist#thread-safety#collections
Back to categoryPractice quiz

Answer

`ArrayList` has no synchronization, so concurrent writes can corrupt its internal state or cause inconsistent reads. Options: external locking, `Collections.synchronizedList`, `CopyOnWriteArrayList` for mostly-reads, or using concurrent queues depending on the use case.

Related questions

Java
HashMap vs ConcurrentHashMap: when should you use each?
#java#collections#concurrency
Java
StringBuilder vs StringBuffer: what’s the difference?
#java#string#performance
Java
`synchronized` vs `ReentrantLock`: what are the differences?
#java#concurrency#locks
Java
Parallel streams: when can they help and what are common pitfalls?
#java#streams#parallel
Java
`List.of(...)`: what kind of list does it create and a common gotcha?
#java#collections#immutability
Java
`synchronized` vs `ReentrantLock` - when would you choose one?
#concurrency#locks#synchronized