...
Code Block | ||
---|---|---|
| ||
Person grandmother = ...new Person() Collection<Person> grandchildren = new ArrayList<Person>(); // Person.getChildren() returns the children as a Collection for (Person child : grandmother.getChildren()) { // Collection.addAll takes another Collection as its only argument grandchildren.addAll(child.getChildren()); } |
...
|
|
...
|
|
|
...
Code Block |
---|
Person hallvard = new Person("H"), anne = new Person("A"), jens = new Person("J") // Person.addChildren takes a Collection-argument and adds them all hallvard.addChildren(Arrays.asList(anne, jens)); // utlize that Arrays.asList is a varargs-method |