Ex 4: Groovy - Groovin' with Groovy | [ Prev | Home | Next ] |
import java.util.* class Erase { public static main(args) { names = [ "Ted", "Fred", "Jed", "Ned" ] System.out.println(names) e = new Erase() short_names = e.filterLongerThan(names, 3) System.out.println (short_names.size()) for (s in short_names) { System.out.println(s) } } public filterLongerThan (strings, length) { result = new ArrayList() for (s in strings) { if (s.length() < length+1) { result.add(s) } } return result } }
(Example 4)
Copyright 2004 by Jim Weirich (Some Rights Reserved) |