I am currently learning a bit about streams. I have the following JSONArray, and I want to be able to retrieve all the distinct xvalues.
 datasets: {
    ds1: {
     xvalues: [
        "(empty)",
        "x1",
        "x2"
      ]
    },
    ds2: {
    xvalues: [
        "(empty)",
        "x1",
        "x2",
        "x3"
      ]
    }
}
I am trying the following code but it doesn't seem quite right....
List<String> xvalues = arrayToStream(datasets)
                .map(JSONObject.class::cast)
                .map(dataset -> {
                    try {
                         return dataset.getJSONArray("xvalues");
                    } catch (JSONException ex) {
                    }
                    return;
            })
            .distinct()
            .collect((Collectors.toList()));
private static Stream<Object> arrayToStream(JSONArray array) {
    return StreamSupport.stream(array.spliterator(), false);
}
 
     
    