# 2D Array of TreeMaps wont access the intValue()

**URL:** <https://discourse.processing.org/t/2d-array-of-treemaps-wont-access-the-intvalue/17245>\
**Category:** Beginners\
**Created:** [January 22, 2020, 5:14am UTC](https://discourse.processing.org/t/2d-array-of-treemaps-wont-access-the-intvalue/17245 "2020-01-22T05:14:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tribblesontoast](https://avatars.discourse-cdn.com/v4/letter/t/e99b99/32.png) [@tribblesontoast](https://discourse.processing.org/u/tribblesontoast)\
**Post date:** [January 22, 2020, 5:14am UTC](https://discourse.processing.org/t/2d-array-of-treemaps-wont-access-the-intvalue/17245/1 "2020-01-22T05:14:48Z")

</div>

Hi all,  
I’m programmatically categorising colours in an image. I’m storing the colours and their values(frequency that they turn up) in a TreeMap. I’m using a single TreeMap for each colour range (ROYGBIV).  
What i’m specifically trying to do is trying to access the _.intValue()_ using that method, of a key in my 2D array of TreeMaps.  
I have an ArrayList with 7 TreeMaps in it (I know, inefficient) and when I use

```auto
myTreeMap.get(arrayIndex).get(key).intValue(); 

```

it throws an error telling me that the _intValue()_ method doesn’t exist. The irritating thing is that when I use a single TreeMap without the extra _.get()_ it works just fine.

Is there a different way I should be accessing this method in this case?  
Help gratefully recieved.

Thanks.

```auto
import java.util.Map;
import java.util.TreeMap;
ArrayList<TreeMap> colourRanges = new ArrayList<TreeMap>();
color tempC;

void setup() {
  colorMode(HSB, 360, 100, 100);
  for (int j = 0; j < 7; j++) colourRanges.add(new TreeMap());
  for (int i = 0; i < 50; i++) populate2DArray();
  for (int i = 0; i < colourRanges.size(); i++) printArray(colourRanges.get(i) + " | " + colourRanges.get(i).size());
}

void populate2DArray() { 
  tempC = color(random(360), random(100), random(100));

  int fam = colorRangeCheck(tempC); //checks the colour range

  if (colourRanges.get(fam).containsKey(tempC)) { //checks if the colour is already in the range
    int value = (colourRanges.get(fam).get(tempC)).intValue(); //gets the current number of entries for this colour
    colourRanges.get(fam).put(tempC, new Integer(value + 1)); //iterates the value by one, re adds
  } else //
  colourRanges.get(fam).put(tempC, 1);
}

int colorRangeCheck(int c) { 
  int range = -1;
  float h = hue(c);

  if (h >= 350 && h <= 360 || 
    h >= 0 && h <= 14) range = 0; //r
  else if (h > 14 && h <= 45) range = 1; //o
  else if (h > 45 && h <= 65) range = 2; //y
  else if (h > 65 && h <= 155) range = 3; //g
  else if (h > 155 && h <= 260) range = 4; //b
  else if (h > 260 && h <= 290) range = 5; //i
  else if (h > 290 && h <= 350) range = 6; //v

  return range;
}

```

edit: typos

---

<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 22, 2020, 5:36am UTC](https://discourse.processing.org/t/2d-array-of-treemaps-wont-access-the-intvalue/17245/2 "2020-01-22T05:36:41Z")

</div>

> [@tribblesontoast](#):
>
> I have an ArrayList with 7 TreeMaps in it…

If you know how many you’re gonna need, you can simplify things a lot by choosing a vanilla array.

> [@tribblesontoast](#):
>
> … it throws an error telling me that the **intValue()** method doesn’t exist.

You didn’t specify the generic datatypes for your TreeMap:

> [@tribblesontoast](#):
>
> `ArrayList<TreeMap> colourRanges = new ArrayList<TreeMap>();`

Which seems like it is the pair `color` & `int`. So, their corresponding wrapper type is Integer:  
`final TreeMap<Integer, Integer>[] colourRanges = new TreeMap[7];`

---

<div class="post-metadata">

**Author:** ![tribblesontoast](https://avatars.discourse-cdn.com/v4/letter/t/e99b99/32.png) [@tribblesontoast](https://discourse.processing.org/u/tribblesontoast)\
**Post date:** [January 22, 2020, 7:01am UTC](https://discourse.processing.org/t/2d-array-of-treemaps-wont-access-the-intvalue/17245/3 "2020-01-22T07:01:04Z")

</div>

Thanks so much GoToLoop. A huge help as always.
