# Finding unique/distinct values in a list

**URL:** https://discourse.processing.org/t/finding-unique-distinct-values-in-a-list/16183
**Category:** Coding Questions
**Created:** [December 6, 2019, 5:39pm UTC](https://discourse.processing.org/t/finding-unique-distinct-values-in-a-list/16183 "2019-12-06T17:39:36Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Lehmoxy](https://avatars.discourse-cdn.com/v4/letter/l/858c86/32.png) [@Lehmoxy](https://discourse.processing.org/u/Lehmoxy)
#### Post date: [December 6, 2019, 5:39pm UTC](https://discourse.processing.org/t/finding-unique-distinct-values-in-a-list/16183/1 "2019-12-06T17:39:36Z")

</div>

Hello all,

I’m wondering if there is a function in processing to find unique/distinct values in arrays/lists. I am trying to make a dropdown menu from an imported data set. For example, if I have an array of 5 elements that contains “bear”, “deer”, “moose”, “moose”, “deer”, I want the function to return “bear”, “deer”, and “moose”. I’m trying to avoid writing my own function.

Many thanks!

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [December 6, 2019, 5:55pm UTC](https://discourse.processing.org/t/finding-unique-distinct-values-in-a-list/16183/2 "2019-12-06T17:55:47Z")

</div>

It’s not really hard when you use hashmap

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [December 6, 2019, 6:36pm UTC](https://discourse.processing.org/t/finding-unique-distinct-values-in-a-list/16183/3 "2019-12-06T18:36:45Z")

</div>

[Processing.org/reference/StringList\_hasValue\_.html](http://Processing.org/reference/StringList_hasValue_.html)  
[Processing.org/reference/StringList\_append\_.html](http://Processing.org/reference/StringList_append_.html)  
[Processing.org/reference/StringList\_array\_.html](http://Processing.org/reference/StringList_array_.html)

```auto
String[] animals = { "bear", "deer", "moose", "moose", "deer" };
StringList unique = new StringList();

println(animals);

for (final String a : animals) if (!unique.hasValue(a)) unique.append(a);
animals = unique.array();

println(animals);

exit();

```

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [December 6, 2019, 6:43pm UTC](https://discourse.processing.org/t/finding-unique-distinct-values-in-a-list/16183/4 "2019-12-06T18:43:34Z")

</div>

[Processing.GitHub.io/processing-javadocs/core/processing/data/StringList.html#getUnique--](http://Processing.GitHub.io/processing-javadocs/core/processing/data/StringList.html#getUnique--)

```auto
String[] animals = { "bear", "deer", "moose", "moose", "deer" };
println(animals);

animals = new StringList(animals).getUnique();
println(animals);

exit();

```
