# BundleCollectionUtil

Artifact: [androidx.media3:media3-common](https://developer.android.com/jetpack/androidx/releases/media3) [View Source](https://cs.android.com/search?q=file:androidx/media3/common/util/BundleCollectionUtil.java+class:androidx.media3.common.util.BundleCollectionUtil)

*** ** * ** ***


```
@UnstableApi
class BundleCollectionUtil
```

<br />

*** ** * ** ***

Utilities for converting collections to and from `https://developer.android.com/reference/android/os/Bundle.html` instances.

## Summary

| ### Public functions |
|---|---|
| `java-static https://developer.android.com/reference/java/util/HashMap.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!>!` | `https://developer.android.com/reference/kotlin/androidx/media3/common/util/BundleCollectionUtil#bundleToStringHashMap(android.os.Bundle)(bundle: https://developer.android.com/reference/android/os/Bundle.html!)` |
| `java-static https://guava.dev/releases/snapshot-android/api/docs/com/google/common/collect/ImmutableMap.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!>!` | `https://developer.android.com/reference/kotlin/androidx/media3/common/util/BundleCollectionUtil#bundleToStringImmutableMap(android.os.Bundle)(bundle: https://developer.android.com/reference/android/os/Bundle.html!)` |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/common/util/BundleCollectionUtil#ensureClassLoader(android.os.Bundle)(bundle: https://developer.android.com/reference/android/os/Bundle.html?)` Sets the application class loader to the given `https://developer.android.com/reference/android/os/Bundle.html` if no class loader is present. |
| `java-static https://guava.dev/releases/snapshot-android/api/docs/com/google/common/collect/ImmutableList.html<T!>!` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/media3/common/util/BundleCollectionUtil#fromBundleList(java.util.function.Function<android.os.Bundle,T>,java.util.List<android.os.Bundle>)( fromBundleFunc: https://developer.android.com/reference/java/util/function/Function.html<https://developer.android.com/reference/android/os/Bundle.html!, T!>!, bundleList: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/android/os/Bundle.html!>! )` Unbundles a list of `https://developer.android.com/reference/android/os/Bundle.html` instances to a list of objects. |
| `java-static https://developer.android.com/reference/android/util/SparseArray.html<T!>!` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/media3/common/util/BundleCollectionUtil#fromBundleSparseArray(java.util.function.Function<android.os.Bundle,T>,android.util.SparseArray<android.os.Bundle>)( fromBundleFunc: https://developer.android.com/reference/java/util/function/Function.html<https://developer.android.com/reference/android/os/Bundle.html!, T!>!, bundleSparseArray: https://developer.android.com/reference/android/util/SparseArray.html<https://developer.android.com/reference/android/os/Bundle.html!>! )` Unbundles a `https://developer.android.com/reference/android/util/SparseArray.html` of `https://developer.android.com/reference/android/os/Bundle.html` instances to a `https://developer.android.com/reference/android/util/SparseArray.html` of objects. |
| `java-static https://developer.android.com/reference/android/os/Bundle.html!` | `https://developer.android.com/reference/kotlin/androidx/media3/common/util/BundleCollectionUtil#getBundleWithDefault(android.os.Bundle,java.lang.String,android.os.Bundle)(bundle: https://developer.android.com/reference/android/os/Bundle.html!, field: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!, defaultValue: https://developer.android.com/reference/android/os/Bundle.html!)` |
| `java-static https://developer.android.com/reference/java/util/ArrayList.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html!>!` | `https://developer.android.com/reference/kotlin/androidx/media3/common/util/BundleCollectionUtil#getIntegerArrayListWithDefault(android.os.Bundle,java.lang.String,java.util.ArrayList<java.lang.Integer>)( bundle: https://developer.android.com/reference/android/os/Bundle.html!, field: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!, defaultValue: https://developer.android.com/reference/java/util/ArrayList.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html!>! )` |
| `java-static https://developer.android.com/reference/android/os/Bundle.html!` | `https://developer.android.com/reference/kotlin/androidx/media3/common/util/BundleCollectionUtil#stringMapToBundle(java.util.Map<java.lang.String,java.lang.String>)(map: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-map/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-map/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!>!)` |
| `java-static https://developer.android.com/reference/java/util/ArrayList.html<https://developer.android.com/reference/android/os/Bundle.html!>!` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/media3/common/util/BundleCollectionUtil#toBundleArrayList(java.util.Collection<T>,java.util.function.Function<T,android.os.Bundle>)( items: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-collection/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-collection/index.html<T!>!, toBundleFunc: https://developer.android.com/reference/java/util/function/Function.html<T!, https://developer.android.com/reference/android/os/Bundle.html!>! )` Bundles a collection of objects to an `https://developer.android.com/reference/java/util/ArrayList.html` of `https://developer.android.com/reference/android/os/Bundle.html` instances so that the returned list can be put to `https://developer.android.com/reference/android/os/Bundle.html` using `https://developer.android.com/reference/android/os/Bundle.html#putParcelableArrayList(java.lang.String, java.util.ArrayList&lt;? extends android.os.Parcelable&gt;)` conveniently. |
| `java-static https://guava.dev/releases/snapshot-android/api/docs/com/google/common/collect/ImmutableList.html<https://developer.android.com/reference/android/os/Bundle.html!>!` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/media3/common/util/BundleCollectionUtil#toBundleList(java.util.List<T>,java.util.function.Function<T,android.os.Bundle>)( list: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<T!>!, toBundleFunc: https://developer.android.com/reference/java/util/function/Function.html<T!, https://developer.android.com/reference/android/os/Bundle.html!>! )` Bundles a list of objects to a list of `https://developer.android.com/reference/android/os/Bundle.html` instances. |
| `java-static https://developer.android.com/reference/android/util/SparseArray.html<https://developer.android.com/reference/android/os/Bundle.html!>!` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/media3/common/util/BundleCollectionUtil#toBundleSparseArray(android.util.SparseArray<T>,java.util.function.Function<T,android.os.Bundle>)( items: https://developer.android.com/reference/android/util/SparseArray.html<T!>!, toBundleFunc: https://developer.android.com/reference/java/util/function/Function.html<T!, https://developer.android.com/reference/android/os/Bundle.html!>! )` Bundles a `https://developer.android.com/reference/android/util/SparseArray.html` of objects to a `https://developer.android.com/reference/android/util/SparseArray.html` of `https://developer.android.com/reference/android/os/Bundle.html` instances so that the returned `https://developer.android.com/reference/android/util/SparseArray.html` can be put to `https://developer.android.com/reference/android/os/Bundle.html` using `https://developer.android.com/reference/android/os/Bundle.html#putSparseParcelableArray(java.lang.String, android.util.SparseArray&lt;? extends android.os.Parcelable&gt;)` conveniently. |

## Public functions

### bundleToStringHashMap

```
java-static fun bundleToStringHashMap(bundle: Bundle!): HashMap<String!, String!>!
```

### bundleToStringImmutableMap

```
java-static fun bundleToStringImmutableMap(bundle: Bundle!): ImmutableMap<String!, String!>!
```

### ensureClassLoader

```
java-static fun ensureClassLoader(bundle: Bundle?): Unit
```

Sets the application class loader to the given `https://developer.android.com/reference/android/os/Bundle.html` if no class loader is present.

This assumes that all classes unparceled from `bundle` are sharing the class loader of `BundleCollectionUtil`.

### fromBundleList

```
java-static fun <T : Any?> fromBundleList(
    fromBundleFunc: Function<Bundle!, T!>!,
    bundleList: (Mutable)List<Bundle!>!
): ImmutableList<T!>!
```

Unbundles a list of `https://developer.android.com/reference/android/os/Bundle.html` instances to a list of objects.

| Parameters |
|---|---|
| `fromBundleFunc: https://developer.android.com/reference/java/util/function/Function.html<https://developer.android.com/reference/android/os/Bundle.html!, T!>!` | Function that specified how to unbundle each item. |
| `bundleList: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/android/os/Bundle.html!>!` | List of `https://developer.android.com/reference/android/os/Bundle.html` instances to be unbundled. |

| Returns |
|---|---|
| `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/collect/ImmutableList.html<T!>!` | The `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/collect/ImmutableList.html` of unbundled items. |

### fromBundleSparseArray

```
java-static fun <T : Any?> fromBundleSparseArray(
    fromBundleFunc: Function<Bundle!, T!>!,
    bundleSparseArray: SparseArray<Bundle!>!
): SparseArray<T!>!
```

Unbundles a `https://developer.android.com/reference/android/util/SparseArray.html` of `https://developer.android.com/reference/android/os/Bundle.html` instances to a `https://developer.android.com/reference/android/util/SparseArray.html` of objects.

| Parameters |
|---|---|
| `fromBundleFunc: https://developer.android.com/reference/java/util/function/Function.html<https://developer.android.com/reference/android/os/Bundle.html!, T!>!` | Function that specified how to unbundle each item. |
| `bundleSparseArray: https://developer.android.com/reference/android/util/SparseArray.html<https://developer.android.com/reference/android/os/Bundle.html!>!` | `https://developer.android.com/reference/android/util/SparseArray.html` of `https://developer.android.com/reference/android/os/Bundle.html` instances to be unbundled. |

| Returns |
|---|---|
| `https://developer.android.com/reference/android/util/SparseArray.html<T!>!` | The `https://developer.android.com/reference/android/util/SparseArray.html` of unbundled items. |

### getBundleWithDefault

```
java-static fun getBundleWithDefault(bundle: Bundle!, field: String!, defaultValue: Bundle!): Bundle!
```

### getIntegerArrayListWithDefault

```
java-static fun getIntegerArrayListWithDefault(
    bundle: Bundle!,
    field: String!,
    defaultValue: ArrayList<Int!>!
): ArrayList<Int!>!
```

### stringMapToBundle

```
java-static fun stringMapToBundle(map: (Mutable)Map<String!, String!>!): Bundle!
```

### toBundleArrayList

```
java-static fun <T : Any?> toBundleArrayList(
    items: (Mutable)Collection<T!>!,
    toBundleFunc: Function<T!, Bundle!>!
): ArrayList<Bundle!>!
```

Bundles a collection of objects to an `https://developer.android.com/reference/java/util/ArrayList.html` of `https://developer.android.com/reference/android/os/Bundle.html` instances so that the returned list can be put to `https://developer.android.com/reference/android/os/Bundle.html` using `https://developer.android.com/reference/android/os/Bundle.html#putParcelableArrayList(java.lang.String, java.util.ArrayList&lt;? extends android.os.Parcelable&gt;)` conveniently.

| Parameters |
|---|---|
| `items: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-collection/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-collection/index.html<T!>!` | Collection of items to be bundled. |
| `toBundleFunc: https://developer.android.com/reference/java/util/function/Function.html<T!, https://developer.android.com/reference/android/os/Bundle.html!>!` | Function that specifies how to bundle each item. |

| Returns |
|---|---|
| `https://developer.android.com/reference/java/util/ArrayList.html<https://developer.android.com/reference/android/os/Bundle.html!>!` | The `https://developer.android.com/reference/java/util/ArrayList.html` of bundled items. |

### toBundleList

```
java-static fun <T : Any?> toBundleList(
    list: (Mutable)List<T!>!,
    toBundleFunc: Function<T!, Bundle!>!
): ImmutableList<Bundle!>!
```

Bundles a list of objects to a list of `https://developer.android.com/reference/android/os/Bundle.html` instances.

| Parameters |
|---|---|
| `list: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<T!>!` | List of items to be bundled. |
| `toBundleFunc: https://developer.android.com/reference/java/util/function/Function.html<T!, https://developer.android.com/reference/android/os/Bundle.html!>!` | Function that specifies how to bundle each item. |

| Returns |
|---|---|
| `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/collect/ImmutableList.html<https://developer.android.com/reference/android/os/Bundle.html!>!` | The `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/collect/ImmutableList.html` of bundled items. |

### toBundleSparseArray

```
java-static fun <T : Any?> toBundleSparseArray(
    items: SparseArray<T!>!,
    toBundleFunc: Function<T!, Bundle!>!
): SparseArray<Bundle!>!
```

Bundles a `https://developer.android.com/reference/android/util/SparseArray.html` of objects to a `https://developer.android.com/reference/android/util/SparseArray.html` of `https://developer.android.com/reference/android/os/Bundle.html` instances so that the returned `https://developer.android.com/reference/android/util/SparseArray.html` can be put to `https://developer.android.com/reference/android/os/Bundle.html` using `https://developer.android.com/reference/android/os/Bundle.html#putSparseParcelableArray(java.lang.String, android.util.SparseArray&lt;? extends android.os.Parcelable&gt;)` conveniently.

| Parameters |
|---|---|
| `items: https://developer.android.com/reference/android/util/SparseArray.html<T!>!` | Collection of items to be bundled. |
| `toBundleFunc: https://developer.android.com/reference/java/util/function/Function.html<T!, https://developer.android.com/reference/android/os/Bundle.html!>!` | Function that specifies how to bundle each item. |

| Returns |
|---|---|
| `https://developer.android.com/reference/android/util/SparseArray.html<https://developer.android.com/reference/android/os/Bundle.html!>!` | The `https://developer.android.com/reference/android/util/SparseArray.html` of bundled items. |