# Data type for ArrayList get() function (class, OOP)

**URL:** <https://discourse.processing.org/t/data-type-for-arraylist-get-function-class-oop/30049>\
**Category:** Coding Questions\
**Created:** [May 11, 2021, 4:29pm UTC](https://discourse.processing.org/t/data-type-for-arraylist-get-function-class-oop/30049 "2021-05-11T16:29:08Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![MBMNGT](https://avatars.discourse-cdn.com/v4/letter/m/90db22/32.png) [@MBMNGT](https://discourse.processing.org/u/MBMNGT)\
**Post date:** [May 11, 2021, 4:29pm UTC](https://discourse.processing.org/t/data-type-for-arraylist-get-function-class-oop/30049/1 "2021-05-11T16:29:08Z")

</div>

Hi  
For Array List functions, I would like to know the type of data returned by the Particle part = particles.get(0) function ?

after some try, ;;; it’s not float or int or string … so, what is ?

Thank in advance

Eric

By example, we could have the following code (see the ??? at the end) :

INITIALIZE SHEET :  
//////////////////////////////////////////////////////////////////////////  
ArrayList\<Class\_B\> class\_b\_elements = new ArrayList\<Class\_B\>();

// CREATE - Class D

Class\_B class\_b\_elementA1 = new Class\_B(BX+10, BY+10, 10, 15, 25, “1”); // (x, y, w, h, couleur, Id)  
Class\_B class\_b\_elementA2 = new Class\_B(BX+25, BY+25, 15, 20, 50, “2”); //  
Class\_B class\_b\_elementA3 = new Class\_B(BX+45, BY+45, 20, 25, 75, “3”); //  
Class\_B class\_b\_elementA4 = new Class\_B(BX+70, BY+70, 25, 30, 100, “4”); //  
Class\_B class\_b\_elementA5 = new Class\_B(BX+100, BY+100, 30, 35, 125, “5”); //

//////////////////////////////////////////////////////////////////////////

CLASS B SHEET :  
//////////////////////////////////////////////////////////////////////////  
class Class\_B {  
float x;  
float y;  
float w;  
float h;  
int couleur;  
String Blabel;  
int tStatus=1; // specifies current status (0=off/not visible, 1=on/visible)  
int hStatus=0; // specifies if current is highlighted (1) or normal (0)

//////////////////////////////////////////////////////////////////////////

Class\_B(float x, float y, float w, float h, int couleur, String Blabel) { // rectangle  
this.x=x;  
this.y=y;  
this.w=w;  
this.h=h;  
this.couleur=couleur;  
this.Blabel=Blabel;  
}

//////////////////////////////////////////////////////////////////////////

??? getClass\_B(int i) {  
Class\_B refClass\_B = class\_b\_elements.get(i);  
return refClass\_B  
}  
} // Class\_B definition

//////////////////////////////////////////////////////////////////////////

MAIN SHEET :  
//////////////////////////////////////////////////////////////////////////  
final int SCREEN\_WIDTH = 800;  
final int SCREEN\_HEIGHT = 500;  
//////////////////////////////////////////////////////////////////////////

void settings() {  
size(SCREEN\_WIDTH, SCREEN\_HEIGHT);  
}

//////////////////////////////////////////////////////////////////////////

void setup() {  
Initialize();  
}

//////////////////////////////////////////////////////////////////////////

for (int i = 0; i\<5; i = i+1){  
??? refClass\_B = getClass\_B(i) {  
println (“refClass\_B:”, refClass\_B);  
}

//////////////////////////////////////////////////////////////////////////

> please format code with \</\> button \* [homework policy](https://discourse.processing.org/faq/#homework) \* [asking questions](https://discourse.processing.org/t/2147)

---

<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:** [May 11, 2021, 4:36pm UTC](https://discourse.processing.org/t/data-type-for-arraylist-get-function-class-oop/30049/2 "2021-05-11T16:36:20Z")

</div>

> [@MBMNGT](#):
>
> ArrayList\<Class\_B\> class\_b\_elements = new ArrayList\<Class\_B\>();

Here the data type that gets returned is Class\_B.

Class\_B is a class that gets defined within your code (so it’s not a data type like int or float).

To understand the concept of class, object and OOP, check [Objects / Processing.org](https://www.processing.org/tutorials/objects/)

---

<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:** [May 11, 2021, 4:37pm UTC](https://discourse.processing.org/t/data-type-for-arraylist-get-function-class-oop/30049/3 "2021-05-11T16:37:27Z")

</div>

> [@MBMNGT](#):
>
> Particle part = particles.get(0) function ?

part is of data type / class part.

part is an object instantiated from the class Particle.

**The method getClass\_B**

This method:

> [@MBMNGT](#):
>
> ??? getClass\_B(int i) {  
> Class\_B refClass\_B = class\_b\_elements.get(i);  
> return refClass\_B  
> }

this would be:

```auto
Class_B getClass_B(int i) {
    Class_B refClass_B = class_b_elements.get(i);
    return refClass_B;
}

```

Oh, and welcome to the forum!

Great to have you here!

Regards,

Chrisir

---

<div class="post-metadata">

**Author:** ![MBMNGT](https://avatars.discourse-cdn.com/v4/letter/m/90db22/32.png) [@MBMNGT](https://discourse.processing.org/u/MBMNGT)\
**Post date:** [May 11, 2021, 5:07pm UTC](https://discourse.processing.org/t/data-type-for-arraylist-get-function-class-oop/30049/4 "2021-05-11T17:07:03Z")

</div>

Thank you for your answer,

but in the main sheet, when I want call the Class\_B getClass\_B(int i) function in the loop for, Processing inform me that “the function “getClass\_B(int)” doest not exist” …

---

<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:** [May 11, 2021, 5:43pm UTC](https://discourse.processing.org/t/data-type-for-arraylist-get-function-class-oop/30049/5 "2021-05-11T17:43:19Z")

</div>

> [@MBMNGT](#):
>
> the function “getClass\_B(int)”

this method is inside the class! (Which is debatable!)

you need

Class\_B dummy= new Class\_B(BX+100, BY+100, 30, 35, 125, “5”); //  
Class\_B refClass\_B = dummy.getClass\_B(i);

**But there are other errors**

but there are other errors; missing function draw(), one { too much…

Initialize() doesn’t exist

the elements are not added to the ArrayList…

* * *

**Here is a version that works**

```auto

// INITIALIZE SHEET : see below: Initialize()
//////////////////////////////////////////////////////////////////////////
ArrayList<Class_B> class_b_elements = new ArrayList<Class_B>();
//////////////////////////////////////////////////////////////////////////

// CLASS B SHEET :
//////////////////////////////////////////////////////////////////////////
class Class_B {
  float x;
  float y;
  float w;
  float h;
  int couleur;
  String Blabel;
  int tStatus=1; // specifies current status (0=off/not visible, 1=on/visible)
  int hStatus=0; // specifies if current is highlighted (1) or normal (0)

  //////////////////////////////////////////////////////////////////////////

  //constr
  Class_B(float x, float y, float w, float h, int couleur, String Blabel) { // rectangle
    this.x=x;
    this.y=y;
    this.w=w;
    this.h=h;
    this.couleur=couleur;
    this.Blabel=Blabel;
  }//constr

  String toString() {
    return
      Blabel
      +": "
      +str(x)
      +","
      +str(y)
      +" etc. ....";
  }//func 

  //////////////////////////////////////////////////////////////////////////
} // Class_B definition

//////////////////////////////////////////////////////////////////////////

// MAIN SHEET :
//////////////////////////////////////////////////////////////////////////
final int SCREEN_WIDTH = 800;
final int SCREEN_HEIGHT = 500;
//////////////////////////////////////////////////////////////////////////

void settings() {
  size(SCREEN_WIDTH, SCREEN_HEIGHT);
}

//////////////////////////////////////////////////////////////////////////

void setup() {
  background(0);

  Initialize();

  for (int i = 0; i<5; i = i+1) {
    Class_B refClass_B = getClass_B(i); 
    println ("refClass_B:", refClass_B.toString());
  }
}

//////////////////////////////////////////////////////////////////////////

void draw() {
  //
  background(0);

  for (int i = 0; i<5; i = i+1) {
    Class_B refClass_B = getClass_B(i); 
    text ("refClass_B: " + refClass_B.toString(), 
      30, i*30+44);
  }
}

//////////////////////////////////////////////////////////////////////////

// CREATE - Class D
void Initialize() {
  float BX = 100; 
  float BY = 100; 
  Class_B class_b_elementA1 = new Class_B(BX+10, BY+10, 10, 15, 25, "1"); // (x, y, w, h, couleur, Id)
  Class_B class_b_elementA2 = new Class_B(BX+25, BY+25, 15, 20, 50, "2"); //
  Class_B class_b_elementA3 = new Class_B(BX+45, BY+45, 20, 25, 75, "3"); //
  Class_B class_b_elementA4 = new Class_B(BX+70, BY+70, 25, 30, 100, "4"); //
  Class_B class_b_elementA5 = new Class_B(BX+100, BY+100, 30, 35, 125, "5"); //

  class_b_elements.add(class_b_elementA1);
  class_b_elements.add(class_b_elementA2);
  class_b_elements.add(class_b_elementA3);
  class_b_elements.add(class_b_elementA4);
  class_b_elements.add(class_b_elementA5);
  //
} //

Class_B getClass_B(int i) {
  Class_B refClass_B = class_b_elements.get(i);
  return refClass_B;
} //
//

```

---

<div class="post-metadata">

**Author:** ![MBMNGT](https://avatars.discourse-cdn.com/v4/letter/m/90db22/32.png) [@MBMNGT](https://discourse.processing.org/u/MBMNGT)\
**Post date:** [May 12, 2021, 9:31am UTC](https://discourse.processing.org/t/data-type-for-arraylist-get-function-class-oop/30049/6 "2021-05-12T09:31:31Z")

</div>

Hi,

Wonderful … 😁

Thank you very much.

In fact, initialy I put the “Class\_B getClass\_B(int i)” function into the Class\_B definition … and I saw that you put it outside …

Have a good day
