Is it possible to have a 2d or 3d StringList, IntList, etc?

edited October 2016 in How To...

It appears that the only way to have a multidimensional, resizable array is to use the incredibly clunky ArrayList. But is it? The documentation for Processing leaves so much to be desired -- who knows what hidden options there may be.
Table appears to be strictly 2D and does not fit my requirements at all well. Am I the only person who finds Processing's data structures frustratingly limited, rigid and user-hostile?


  • It has never been a limitation for me. If I don't like what I see, I will write my own Java classes or borrow java code available in the web. If you can do it in Java, you can do it in processing.


  • If I wanted to learn Java, I would learn Java. Processing is supposed to be a simpler alternative but so far I'm finding that every single blasted thing I want to do requires me to drop down into Java. I am NOT amused.

  •     ArrayList<Integer> [][][] a1 = new ArrayList[7][7][7];
        void setup() {
        void draw() {
  • maybe it would help to tell us what you are planning.

    in my experience it's rare that people really need more than 4 dimensions

    (I mean 4 dimensions, what is that supposed to be? The stages of a game in 3D chess?)

  • You are being unfair to Processing.

    Processing does not have a multidimensional, resizable array data structure but then neither does Java. So if you want one, you have to build it yourself or persuade someone else to do it for you.

    All programming languages provide a range of data structures but it is IMPOSSIBLE for the developers to predict, never mind provide every possible data structure that a programmer might want to use.

  • hashmap? using a compound key?

    HashMap<String, Int> hash3d = new HashMap<String, Int>();
    void put(int a, int b, int c, int value) {
        String key = a + "_" + b + "_" + c;
        hash3d.put(key, value);
    int get(int a, int b, int c) {
        String key = a + "_" + b + "_" + c;
        return hash3d.get(key);

    untested. also less efficient than an arraylist, i guess. and lacks methods for iterating. but if all you want is to be able to add things to a 3d array and take them out again, without worrying about sizing the arrays, then the above will do.

    Am I the only person who finds Processing's data structures frustratingly limited, rigid and user-hostile?

    well, the opposite of this is having Generic classes like ArrayList but apparently that is "incredibly clunky".

  • edited October 2016

    This will be a much more productive conversation if you give the scenario and preferably share actual code.

    E.g., if you want a 2D IntList so that you can pass xy objects that refer to the screen around, use a PVector (or ArrayList<PVector>) instead.

    If you need a resizeable 3D Stringlist... what are you doing with it? Attaching a text label to each voxel in a resizeable 3D space? There may actual be much better ways of achieving what you want -- usually a simple list (ArrayList) that contains a custom multidimensional object (MyVoxelText). There are many examples of what this code looks like in practice, but again, your scenario is the place to start.

    And, if all else fails, try a different code paradigm. Python and R (to give two very different language examples) both make multidimensional resizable arrays relatively painless -- however they are not "belt-AND-suspenders" languages, like Java, which as a language emphasizes code safety and security over do-what-you-want.

  • edited October 2016

    Quark, I do not expect every possible data structure to be provided, but a resizable multidimensional array strikes me as rather fundamental. And I didn't say I need more than 4 dimensions. But when I see nothing in the documentation that indicates that a StringArray would work in more than 1 dimension, and I cant find any examples of it, and I can not personally get it to work when I try it, I think I might be forgiven for assuming it's just not set up that way.

  • edited October 2016

    ... but a resizable multidimensional array strikes me as rather fundamental.

    Processing's API does provide functions to deal w/ Java arrays:

    For example, append() & shorten():

    However, due to the fact a whole new array has to be created, and the old content transferred to that, it isn't advisable to call those functions all the time @ 60 FPS.

    But, if that's sporadically, for example, when a mouse or keyboard input event is triggered, it's totally reasonable to rely on those array functions, as to enjoy array's simpler [] syntax: O:-)

  • @rickhatfield Please note that Processing was originally built for the purpose of simplifying Graphics in java, which it did do.
    The rest has remained mostly the same - good old java.

Sign In or Register to comment.