Skip to content
MarkyVasconcelos edited this page Dec 21, 2010 · 1 revision

Introduction

Some common methods utils for Collections of elements.

The class CollectionsUtil has some methods to use over collections.

And these are:

*split(List{{{}}} l, String field)

This method returns a List with the values of the attribute 'field' gettered from the object of the list 'l'.

As example, with model Person.

public class Person {
	private String name;
	private int age;
	public Person(String str, double d) {
		this.name = str;
		this.age = (int) d;
	}
}

If we have a list of Person and want a list with all ages, we do this:

List<Person> list = new ArrayList<Person>();
list.add(new Person("A", 10.0));
list.add(new Person("B", 20.0));
list.add(new Person("C", 30.0));
list.add(new Person("D", 40.0));
list.add(new Person("E", 50.0));

List<Double> ages = CollectionsUtil.split(list, "age");

And 'ages' will have the elements:

[10.0,20.0,30.0,40.0,50.0]

Another feature for Collections, see AggregateFunctions

Some others methods will be explained in time.

Clone this wiki locally