Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
ハッシュマップまたはツリーマップが既に存在する場合、以前のキー値が置き換えられないようにするにはどうすればよいですか?また、例外をスローしてユーザーに通知したいと考えています。
myMap.putIfAbsent(key, val) を使用
これは 1.8 から Map インターフェイスに導入されました。
* @since 1.8 */ default V putIfAbsent(K key, V value) {