# Is it possible to use a string for a type like "int something+""+i = i"

**URL:** <https://discourse.processing.org/t/is-it-possible-to-use-a-string-for-a-type-like-int-something-i-i/40624>\
**Category:** Beginners\
**Created:** [January 17, 2023, 8:43pm UTC](https://discourse.processing.org/t/is-it-possible-to-use-a-string-for-a-type-like-int-something-i-i/40624 "2023-01-17T20:43:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aryszin](https://avatars.discourse-cdn.com/v4/letter/a/ec9cab/32.png) [@Aryszin](https://discourse.processing.org/u/Aryszin)\
**Post date:** [January 17, 2023, 8:43pm UTC](https://discourse.processing.org/t/is-it-possible-to-use-a-string-for-a-type-like-int-something-i-i/40624/1 "2023-01-17T20:43:51Z")

</div>

Hello!  
Is it possible to do this?

```auto
int something, something1, something2, something3, something4, something5;

for(int i = 0; i < 5; i++) {
      something+""+i = i;
}

```

\*so it uses all 5 variables and doesnt make the variable “something” 5!, so it makes all 5 variables to 1,2,3,4 & 5!

---

<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 17, 2023, 9:06pm UTC](https://discourse.processing.org/t/is-it-possible-to-use-a-string-for-a-type-like-int-something-i-i/40624/3 "2023-01-17T21:06:40Z")

</div>

An IntDict container is as close as we can get in Processing:

> **[IntDict / Reference](https://processing.org/reference/IntDict.html)**
>
> A simple class to use a String as a lookup for an int value. String "keys" are associated with integer values.

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [January 17, 2023, 9:33pm UTC](https://discourse.processing.org/t/is-it-possible-to-use-a-string-for-a-type-like-int-something-i-i/40624/4 "2023-01-17T21:33:00Z")

</div>

You can’t really build variables like this.

I think one way very similar is an array:

An array is a list.

see [Array / Reference / Processing.org](https://processing.org/reference/Array.html)

This list has one name, but being a list, it has different slots (lines) that you can access via their line number (index).

```auto
int[] something=new int [5]; // array 

for (int i = 0; i < 5; i++) {
  something[i] = i;
}

printArray(something); 

println("-----------------------------------");

println( something[2] );

println("-----------------------------------");

for (int i = 0; i < 5; i++) {
  something[i] = i*10;
}

printArray(something);

```

This gives you an output:

```auto

[0] 0
[1] 1
[2] 2
[3] 3
[4] 4
-----------------------------------
[0] 0
[1] 10
[2] 20
[3] 30
[4] 40

```

(Output similar, older version)

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [January 17, 2023, 9:37pm UTC](https://discourse.processing.org/t/is-it-possible-to-use-a-string-for-a-type-like-int-something-i-i/40624/5 "2023-01-17T21:37:33Z")

</div>

As has been pointed out by gotoLoop, there is also  
IntDict.

You can use a **String** as a lookup for an int value.  
String “keys” are associated with integer values.  
FloatDict and HashMap are similar.

see [IntDict / Reference / Processing.org](https://processing.org/reference/IntDict.html)

```auto
IntDict inventory;

void setup() {
  size(200, 200);
  inventory = new IntDict();
  inventory.set("cd", 84);
  inventory.set("tapes", 15);
  inventory.set("records", 102);
  println(inventory);
  // noLoop();
  fill(0);
  textAlign(CENTER);
}

void draw() {
  background (255); 

  int numRecords = inventory.get("records");
  text(numRecords, width/2, height/2);

  int numCD = inventory.get("cd");
  text(numCD, width/2, height/2+22);
}

```
