Here I show you an example based on the data you already have:
import java.util.*;
public class HelloWorld{
public static void main(String []args){
Data dato1 = new Data("Producto1",1,10.0);
Data dato2 = new Data("Producto2",2,20.0);
Data dato3 = new Data("Producto3",3,30.0);
ArrayList<Data> arrayList = new ArrayList<Data>();
arrayList.add(dato1);
arrayList.add(dato2);
arrayList.add(dato3);
Double total = 0.00;
for (Data data : arrayList) {
total += data.Precio;
}
System.out.println(total);
}
}
class Data {
String Nombre;
Integer CodProducto;
Double Precio;
Data(String nombre,Integer codProducto,Double precio){
this.Nombre = nombre;
this.CodProducto = codProducto;
this.Precio = precio;
}
}
Here's the example