# How to extract values from custom class?

**URL:** <https://discourse.processing.org/t/how-to-extract-values-from-custom-class/28268>\
**Category:** Beginners\
**Created:** [March 4, 2021, 9:21pm UTC](https://discourse.processing.org/t/how-to-extract-values-from-custom-class/28268 "2021-03-04T21:21:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tea\_tree](https://avatars.discourse-cdn.com/v4/letter/t/d6d6ee/32.png) [@tea\_tree](https://discourse.processing.org/u/tea_tree)\
**Post date:** [March 4, 2021, 9:21pm UTC](https://discourse.processing.org/t/how-to-extract-values-from-custom-class/28268/1 "2021-03-04T21:21:38Z")

</div>

I have a class with some variables like so

```auto
class Foo {
  // Instance Variables
  String myString;
  int myNums1;
  int myNums2;

  // Constructor Declaration of Class
  Flow(String myString, int myNums){
    this.myString = myString;
    this.myNums1 = myNums1;
    this.myNums2 = myNums2;
  }
}

```

In my draw function, I would like to access the myNums variable.

```auto
// create Foo instance foo
for (int i=0; i<myTable.getRowCount(); i++) {
    String myString = myTable.getString(i, 0); //myTable is defined elsewhere and works just fine
    int myNums = myTable.getInt(i,1);
}

draw(){
numFlag = 1;
for (int i=0; i < foo.size(); i++){
float myWeight = map(foo.get(numFlag).get(i), 0, 10000, 0, 50);
strokeWeight(myWeight);
// draw something here...
}

```

How can I get the ith value of the numFlagth variable?

---

<div class="post-metadata">

**Author:** ![s31](https://avatars.discourse-cdn.com/v4/letter/s/b77776/32.png) [@s31](https://discourse.processing.org/u/s31)\
**Post date:** [March 4, 2021, 10:57pm UTC](https://discourse.processing.org/t/how-to-extract-values-from-custom-class/28268/2 "2021-03-04T22:57:05Z")

</div>

maybe try returning the values with [return](https://processing.org/reference/return.html)

---

<div class="post-metadata">

**Author:** ![tea\_tree](https://avatars.discourse-cdn.com/v4/letter/t/d6d6ee/32.png) [@tea\_tree](https://discourse.processing.org/u/tea_tree)\
**Post date:** [March 4, 2021, 11:23pm UTC](https://discourse.processing.org/t/how-to-extract-values-from-custom-class/28268/3 "2021-03-04T23:23:46Z")

</div>

I think I figured it out myself. I ended up adding an ArrayList into the class and then called it with

float myWeight = map(foo.get(numFlag).myArrayList.get(i), 0, 10000, 0, 50);

Thanks for your help!

---

<div class="post-metadata">

**Author:** ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)\
**Post date:** [March 5, 2021, 9:50am UTC](https://discourse.processing.org/t/how-to-extract-values-from-custom-class/28268/4 "2021-03-05T09:50:44Z")

</div>

When using classes, you can extract varriables from them by using:

```auto
ArrayList<CustomClass> obj = new ArrayList<CustomClass>();
obj.add(new CustomClass("parameter 1"));
println(obj.get(0).varriableName);
//or if using an ArrayList
printArray(obj.get(0).arrayListName);
//or if using ArrayList element:
println(obj.get(0).arrayListName.get(<id>));

```

used in code:

```auto
ArrayList<CustomClass> obj = new ArrayList<CustomClass>();
void setup() {
  obj.add(new CustomClass("parameter 1"));
  println(obj.get(0).varriableName);
  //or if using an ArrayList
  printArray(obj.get(0).arrayListName);
  //or if using ArrayList element:
  println(obj.get(0).arrayListName.get(2));
}
class CustomClass {
  float varriableName = 123;
  ArrayList<Float> arrayListName = new ArrayList<Float>();
  CustomClass(String randomTxt) {
    if (randomTxt.equals("hax")) println("Hi");
    for (int i = 0; i < randomTxt.length(); i++) arrayListName.add(random(255));
  }
}

```
