Assume list of integral, we want a subset of list with only non-negative values. In Java:
Iterator it = list.iterator();
List newList = new ArrayList();
while(it.hasNext())
{
Integer i = (Integer) it.next();
if(i.intValue() >= 0)
{
newList.add(i);
}
}
The Smalltalk equivalent is:
| newList |
newList := list collect: [:x | x >= 0].
The conceptual load in the Java version is an order of magnitude higher as I have to deal with setting up a loop, determining a good end condition, the duality of objects and primitives, the allocation of the new list container including the selection of an appropriate implementation, setting up the test that determines inclusion, doing the cast from Object down to Integer. There are a *lot* of things to get wrong in the Java version. In fact, the Java version will go terribly wrong if there is some other kind of number representation in the list, like a Long. Maybe I need to go back and check for that case.