0

This is the class where I declare several INT variables that contain positions and then add them into an arraylist but I would like to do it in some kind of loop and not add line by line

class Ejecutar {

    
    private int B1 = 0;
    private int B2 = 2;
    private int B3 = 3;
    private int B4 = 8;
    private int B5 = 9;
    private int B6 = 11;
    private int B7 = 12;
    private int B8 = 17;

    
    private  ArrayList<Integer> arreglo_posiciones = new ArrList<Integer>();

    
    public Ejecutar() {
        
    }
    
    
    public void cargarArregloPosiciones() { 
        this.arreglo_posiciones.add(this.B1);
        this.arreglo_posiciones.add(this.B2);
        this.arreglo_posiciones.add(this.B3);
        this.arreglo_posiciones.add(this.B4);
        this.arreglo_posiciones.add(this.B5);
        this.arreglo_posiciones.add(this.B6);
        this.arreglo_posiciones.add(this.B7);
        this.arreglo_posiciones.add(this.B8); 
    }

}
    

I want to add these variables with some kind of loop without the need to add them line by line

imnachox2
  • 5
  • 3

0 Answers0