jillesvangurp/jsonj

reversing array etc

Closed this issue · 2 comments

Would be nice if there would be support for reversing an array (or also other sorted collections?)

public static JsonArray reverse(JsonArray arr) {
    JsonArray res = new JsonArray();
    for (int i = arr.size() - 1; i >= 0; i--) {
        JsonElement el = arr.get(i);
        res.add(el);
    }
    return res;
}

You should be able to use Collections.reverse or Collections.sort.

oh, ok