# Java equivalent of js object\[key\] lookup

**URL:** <https://discourse.processing.org/t/java-equivalent-of-js-object-key-lookup/7345>\
**Category:** Beginners\
**Created:** [January 9, 2019, 4:00am UTC](https://discourse.processing.org/t/java-equivalent-of-js-object-key-lookup/7345 "2019-01-09T04:00:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![PHuzzeyMusic](https://avatars.discourse-cdn.com/v4/letter/p/3be4f8/32.png) [@PHuzzeyMusic](https://discourse.processing.org/u/PHuzzeyMusic)\
**Post date:** [January 9, 2019, 4:00am UTC](https://discourse.processing.org/t/java-equivalent-of-js-object-key-lookup/7345/1 "2019-01-09T04:00:49Z")

</div>

Just started making this Java Swing interface to control lots of parameters in a separate window from my sketch. Is there a way in Java to make references closer to this old jQuery code I made a  
while ago with ToneJS:

the dataset comes from my custom html attributes.  
`

```
effects = {"delay": delay, "trem": trem, "soundFilter": soundFilter};

$("input[type='range']").on("input", function() {
        effects[this.dataset.module][this.id][this.dataset.suffix] = this.value;
    }
});
`

```

Module = effects key(ref to object to modify), id = param(time, rate, etc), suffix is ‘value’ or ‘’ if no value suffix needed.

This handled lots of sliders and worked as I expected without the need of if statements or a switch statement.

Is it possible to do something similar in Java instead of object(dot)property?

---

<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:** [January 9, 2019, 5:38pm UTC](https://discourse.processing.org/t/java-equivalent-of-js-object-key-lookup/7345/2 "2019-01-09T17:38:53Z")

</div>

> [@PHuzzeyMusic](#):
>
> `effects = { "delay": delay, "trem": trem, "soundFilter": soundFilter };`

Since the variables’ being assigned to the object’s properties match the names of the properties, we can use a much shorter object creation for it: 😉

`effects = { delay, trem, soundFilter };`

> **[Object initializer - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer#New_notations_in_ECMAScript_2015)**
>
> An object initializer is a comma-delimited list of zero or more pairs of property names and associated values of an object, enclosed in curly braces ({}). Objects can also be initialized using Object.create() or by invoking a constructor function...

Each field (property) of a Java object got its own datatype.  
And Java objects are created via instantiating a class.  
Which in turn got the description of the fields which will be present on that object.

If by chance the properties of that _effects_ object share the same compatible datatype, we can use a HashMap container to hold those properties’ values: #️⃣

> **[HashMap / Reference](https://processing.org/reference/HashMap.html)**
>
> A HashMap stores a collection of objects, each referenced by a key. This is similar to an Array, only instead of accessing elements with a numeric index, a String is used. (If you…
