---
title: Validated Collections
---

Fzzy Config has validation for lists, maps, and sets. Each of these has intricacies that are more thoroughly explained in the documentation:

[Validated Collections 🗗](https://fzzyhmstrs.github.io/fconfig/-fzzy%20-config/me.fzzyhmstrs.fzzy_config.validation.collection/index.html)

<Callout variant="info">
Validated collections implement their respective collection type (list, set, map), so can be used directly as such instead of having to <code>.get()</code> the wrapped collection first.
</Callout>

### Validation Conversion
Any `ValidatedField` can be converted into a list or set using the `toList()` and `toSet()` methods, respectively. In addition, collections can be converted to [ValidatedChoice](Choices) using their `toChoices()` method. The `ValidatedField` is backing validation for the resulting collection.

<CodeTabs>

```java !!tabs Java
//wraps the vararg valued provided with a blank validated field (identifiers in this case). validation with actual bounds and logic can of course be used too
public ValidatedList<Identifier> listFromField = new ValidatedIdentifier().toList(Identifier.of("stick"), Identifier.of("blaze_rod"));
```

```kotlin !!tabs Kotlin
//wraps the vararg valued provided with a blank validated field (identifiers in this case). validation with actual bounds and logic can of course be used too
var listFromField = ValidatedIdentifier().toList(Identifier.of("stick"), Identifier.of("blaze_rod"))
```

</CodeTabs>

### Static Initializers
`ValidatedList` and Set have static methods that initialize collections of common types, much like java `List.of()` or kotlin `listOf()`.

<CodeTabs>

```java !!tabs Java
public ValidatedList<Integer> validatedIntList = ValidatedList.ofInt(1, 2, 5, 10);
public ValidatedSet<Integer> validatedIntSet = ValidatedSet.ofInt(1, 2, 5, 10);
```

```kotlin !!tabs Kotlin
var validatedIntList = ValidatedList.ofInt(1, 2, 5, 10)
var validatedIntSet = ValidatedSet.ofInt(1, 2, 5, 10)
```

</CodeTabs>

### Map Builders
Validated Maps have builders for simple creation. These builders are "staged", walking you through each stage needed to build it, so are technically pseudo-builders.

<CodeTabs>

```java !!tabs Java
public ValidatedMap<Integer, Boolean> myMap = (new ValidatedMap.Builder())
        .keyHandler(new ValidatedInt(2, 100, 0)) //first comes the key handler. The default value for this will be the initial value stored in the key when a new entry is added.
        .valueHandler(new ValidatedBoolean()) //next the value handler.
        .defaults(Map.of(5, true, 10, false, 15, true)) //default map values can be set a variety of ways
        .build(); //build!
```

```kotlin !!tabs Kotlin
var myMap: ValidatedMap<Int, Boolean> = ValidatedMap.Builder()
    .keyHandler(ValidatedInt(2, 100, 0)) //first comes the key handler. The default value for this will be the initial value stored in the key when a new entry is added.
    .valueHandler(ValidatedBoolean()) //next the value handler.
    .defaults(mapOf(5 to true, 10 to false, 15 to true)) //default map values can be set a variety of ways
    .build() //build!
```

</CodeTabs>

<Callout>
See the documentation pages for <a target="_blank" rel="noopener" href="https://fzzyhmstrs.github.io/fconfig/-fzzy%20-config/me.fzzyhmstrs.fzzy_config.validation.collection/-validated-list/index.html">List 🗗</a>, <a target="_blank" rel="noopener" href="https://fzzyhmstrs.github.io/fconfig/-fzzy%20-config/me.fzzyhmstrs.fzzy_config.validation.collection/-validated-set/index.html">Set 🗗</a>, <a target="_blank" rel="noopener" href="https://fzzyhmstrs.github.io/fconfig/-fzzy%20-config/me.fzzyhmstrs.fzzy_config.validation.collection/-validated-map/index.html">Map 🗗</a>, <a target="_blank" rel="noopener" href="https://fzzyhmstrs.github.io/fconfig/-fzzy%20-config/me.fzzyhmstrs.fzzy_config.validation.collection/-validated-enum-map/index.html">Enum Map 🗗</a>, <a target="_blank" rel="noopener" href="https://fzzyhmstrs.github.io/fconfig/-fzzy%20-config/me.fzzyhmstrs.fzzy_config.validation.collection/-validated-identifier-map/index.html">Identifier Map 🗗</a>, <a target="_blank" rel="noopener" href="https://fzzyhmstrs.github.io/fconfig/-fzzy%20-config/me.fzzyhmstrs.fzzy_config.validation.collection/-validated-string-map/index.html">String Map 🗗</a>
</Callout>