import java.util.*
class Erase {
public static void main(String[] args) {
List names = new ArrayList()
names.add("Ted")
names.add("Fred")
names.add("Jed")
names.add("Ned")
System.out.println(names)
Erase e = new Erase()
List short_names = e.filterLongerThan(names, 3)
System.out.println (short_names.size())
for (s in short_names) {
System.out.println(s)
}
}
public List filterLongerThan (List strings, int length) {
List result = new ArrayList()
for (s in strings) {
if (s.length() < length+1) {
result.add(s)
}
}
return result
}
}
- Perhaps we don’t need all those type annotations …