本页尚未翻译,因此以英文显示。 参与翻译

fxOmit

Returns a copy of a Map without the given keys.

Map<K, V> fxOmit<K, V>(Iterable<K> keysToOmit, Map<K, V> map)

Lecture

fxOmit builds a brand-new Map containing every entry of the original except the keys you list — the source map is never mutated. Keys in keysToOmit that don't actually exist in the map are simply ignored; there's no error for "extra" keys to remove.

It's a common redaction/serialization tool: strip a password hash before logging a user object, drop an internal field before sending a response, and so on. Pair it with map() to redact a whole list of maps at once.

Demo 1 · Basics

Demo 2 · Redacting a whole list

Try it yourself

Exercise: use fxOmit to drop the 'debug' key from config.

Related: fxPick — the inverse: keep only some keys · fxOmitBy — drop by predicate instead of key list · fxCompactObject — drop null-valued keys · fxFromEntries — build a Map from scratch