标签:eal print list pat count() ret demo alt int
1.链表的使用
import java.util.ArrayList; import java.util.List; class Item { private int count; public Item(int count) { this.count = count; } public int getCount() { return count; } } class Meal { private ArrayList<Item> items = new ArrayList<Item>(); void addItem(Item item) { items.add(item); } int sum_count() { int count = 0; for (Item i : items) { count += i.getCount(); } return count; } } public class BuilderPatternDemo { public static void main(String args[]) { Item item1 = new Item(10); Item item2 = new Item(20); Item item3 = new Item(30); Meal meal1 = new Meal(); meal1.addItem(item1); meal1.addItem(item2); meal1.addItem(item3); System.out.println("Sum=" + meal1.sum_count()); } }
标签:eal print list pat count() ret demo alt int
原文地址:https://www.cnblogs.com/hellokitty2/p/10663078.html