//Sum all widths
//Note: if needed add "getWidth" getter to rectangle for this sample
List<Rectangle> rectangles = Rectangle.sampleList();
println("Rectangles: " + listToString(rectangles));
int sum = 0;
for (Rectangle eachRec: rectangles) {
sum += eachRec.getWidth();
}
println("Sum of All Widths: " + sum);
Rectangles: [10x1, 20x2, 30x3, 40x4]
Sum of All Widths: 100
Introduction To Objects With Java
(Chapter 701 - Lists)