# How to read in StringArray tag into Java List

**URL:** <https://forum.inductiveautomation.com/t/how-to-read-in-stringarray-tag-into-java-list/58367>\
**Category:** Module Development\
**Tags:** ignition80\
**Created:** [April 12, 2022, 5:52pm UTC](https://forum.inductiveautomation.com/t/how-to-read-in-stringarray-tag-into-java-list/58367 "2022-04-12T17:52:59Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sholom\_Ellenbogen](https://avatars.discourse-cdn.com/v4/letter/s/c37758/32.png) [@Sholom\_Ellenbogen](https://forum.inductiveautomation.com/u/Sholom_Ellenbogen)\
**Post date:** [April 12, 2022, 5:52pm UTC](https://forum.inductiveautomation.com/t/how-to-read-in-stringarray-tag-into-java-list/58367/1 "2022-04-12T17:52:59Z")

</div>

Using the Tagprovider’s readAsync method, how would I read in a tag that is of the StringArray type into a Java List

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [April 12, 2022, 6:49pm UTC](https://forum.inductiveautomation.com/t/how-to-read-in-stringarray-tag-into-java-list/58367/2 "2022-04-12T18:49:30Z")

</div>

`readAsync` will return a list of QualifiedValues; extract the value with `getValue`, and then the inner `Object` should be an `Array<String>`; you could then use `Arrays.asList()` to wrap the array in a list.

---

<div class="post-metadata">

**Author:** ![Sholom\_Ellenbogen](https://avatars.discourse-cdn.com/v4/letter/s/c37758/32.png) [@Sholom\_Ellenbogen](https://forum.inductiveautomation.com/u/Sholom_Ellenbogen)\
**Post date:** [April 12, 2022, 7:01pm UTC](https://forum.inductiveautomation.com/t/how-to-read-in-stringarray-tag-into-java-list/58367/3 "2022-04-12T19:01:03Z")

</div>

I tried this and it didn’t seem to work. I will post my code below so you can confirm if I am doing what you suggested properly.

I set the tag’s value to be [“a”, “b”, “c”, “d”, “e”] for this test.

```auto
List<QualifiedValue> values = provider.readAsync(paths, SecurityContext.emptyContext()).get(timeout, TimeUnit.MILLISECONDS);
List<Object> readList = Arrays.asList(values.get(0).getValue());

if (readList.get(0).equals("a")) {
	log.info("WORKED?");
} else {
	log.info("NO WORKY");
}

```

Note that I read in readList as `List<Object>` because it complains if I try to do it directly to `List<String>`

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [April 12, 2022, 7:06pm UTC](https://forum.inductiveautomation.com/t/how-to-read-in-stringarray-tag-into-java-list/58367/4 "2022-04-12T19:06:45Z")

</div>

You can log the actual value of `values.get(0).getValue()` and it’s type to see what you’re actually getting?

I’m not especially familiar with the tag system, so my assumption was that it returned a vanilla string array, but it may be some more specific UA datatype still.

---

<div class="post-metadata">

**Author:** ![Sholom\_Ellenbogen](https://avatars.discourse-cdn.com/v4/letter/s/c37758/32.png) [@Sholom\_Ellenbogen](https://forum.inductiveautomation.com/u/Sholom_Ellenbogen)\
**Post date:** [April 12, 2022, 7:16pm UTC](https://forum.inductiveautomation.com/t/how-to-read-in-stringarray-tag-into-java-list/58367/5 "2022-04-12T19:16:25Z")

</div>

This is the code:

```auto
List<QualifiedValue> values = provider.readAsync(paths, SecurityContext.emptyContext()).get(timeout, TimeUnit.MILLISECONDS);
log.info("LOOK HERE 1: " + values.get(0));
log.info("LOOK HERE 2: " + values.get(0).getValue());
log.info("LOOK HERE 3: " + values.get(0).getClass());

```

And the logs are below:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/4/74beebf416fd1b703f8e95a2effb54c0f438bc5c.png)

---

<div class="post-metadata">

**Author:** ![Sholom\_Ellenbogen](https://avatars.discourse-cdn.com/v4/letter/s/c37758/32.png) [@Sholom\_Ellenbogen](https://forum.inductiveautomation.com/u/Sholom_Ellenbogen)\
**Post date:** [April 12, 2022, 7:22pm UTC](https://forum.inductiveautomation.com/t/how-to-read-in-stringarray-tag-into-java-list/58367/6 "2022-04-12T19:22:11Z")

</div>

I also just logged the `values.get(0).getValue().getClass()` and it logged as “[Ljava.lang.String;”

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [April 12, 2022, 7:31pm UTC](https://forum.inductiveautomation.com/t/how-to-read-in-stringarray-tag-into-java-list/58367/7 "2022-04-12T19:31:49Z")

</div>

That’s the toString() for a `String[]`, alright. Which should be just fine to pass to `Arrays.asList`.

Try logging the individual elements of the array? Make sure they’re what you expect?

---

<div class="post-metadata">

**Author:** ![Sholom\_Ellenbogen](https://avatars.discourse-cdn.com/v4/letter/s/c37758/32.png) [@Sholom\_Ellenbogen](https://forum.inductiveautomation.com/u/Sholom_Ellenbogen)\
**Post date:** [April 13, 2022, 11:19am UTC](https://forum.inductiveautomation.com/t/how-to-read-in-stringarray-tag-into-java-list/58367/8 "2022-04-13T11:19:47Z")

</div>

I thought so too but I can’t seem to get it to log the value. Below is the code I tried:

```auto
List<QualifiedValue> values = provider.readAsync(paths, SecurityContext.emptyContext()).get(timeout, TimeUnit.MILLISECONDS);
List<Object> values2 = Arrays.asList(values.get(0).getValue());
log.info("LOOK HERE 4: " + values2.get(0));
log.info("LOOK HERE 5: " + values2.get(0).toString());
log.info("LOOK HERE 6: " + (String) values2.get(0));

```

Below is the log:

```auto
LOOK HERE 5: [Ljava.lang.String;@49bfa951
LOOK HERE 4: [Ljava.lang.String;@49bfa951

```

and LOOK HERE 6 (`(String) values2.get(0)`) produces a cast exception `[Ljava.lang.String; cannot be cast to class java.lang.String`

Part of the issue seems is that the result of `values2.get(0)` returns a `String[]` but java thinks its a String or Object not an array so it wont compile if I tried to access it as I would an array. But if I cannot access it as I would an array then how am I supposed to get the value?

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [April 13, 2022, 11:48am UTC](https://forum.inductiveautomation.com/t/how-to-read-in-stringarray-tag-into-java-list/58367/9 "2022-04-13T11:48:15Z")

</div>

```auto
List<QualifiedValue> values = 
    provider.readAsync(paths, SecurityContext.emptyContext())
        .get(timeout, TimeUnit.MILLISECONDS);

String[] ss = (String[]) values.get(0).getValue();

// option 1
List<String> list1 = List.of(ss);

// option 2
List<String> list2 = Arrays.stream(ss).collect(Collectors.toList());

```
