Lists & Iterators
- Variable arguments (Varargs)
A program having an array as parameter is similar to a program having 0 to N parameter(s), i.e. a variable number of arguments, what conduces to equivalent notations:
void printAll(String[] vs) { ... } // definition
printAll(new String[]{"this","is","an","example"}); // use
// is equivalent to:
void printAll(String ... vs);
printAll("this","is","an","example");
- Reification of algorithms/functions
'Reification' means 'to transform into an object' and mathematical function (e.g. Comparator) can be reified into:
interface Function<T,R> { // java.util.function
public R apply(T x); }
Function<Double,Double> f = new Function<Double,Double>() {
public Double apply(Double x) { return 2.0*x+1.0; }};
System.out.println( f.apply(2.0) );
- Using functional programming
Finally, a comparator is a function and can be written as follow:
lst.sort((o1,o2)->o2.compare(o1));
System.out.println( lst );
Java jva jav laurent thiry uha enseignant ensisa ecole school national alsace programmation objet approche mulhouse france java object programming oriented
Java jva jav laurent thiry uha enseignant ensisa ecole school national alsace programmation objet approche mulhouse france java object programming oriented
Java jva jav laurent thiry uha enseignant ensisa ecole school national alsace programmation objet approche mulhouse france java object programming oriented
Java jva jav laurent thiry uha enseignant ensisa ecole school national alsace programmation objet approche mulhouse france java object programming oriented
Java jva jav laurent thiry uha enseignant ensisa ecole school national alsace programmation objet approche mulhouse france java object programming oriented
Java jva jav laurent thiry uha enseignant ensisa ecole school national alsace programmation objet approche mulhouse france java object programming oriented
Java jva jav laurent thiry uha enseignant ensisa ecole school national alsace programmation objet approche mulhouse france java object programming oriented
Java jva jav laurent thiry uha enseignant ensisa ecole school national alsace programmation objet approche mulhouse france java object programming oriented
Java jva jav laurent thiry uha enseignant ensisa ecole school national alsace programmation objet approche mulhouse france java object programming oriented
Java jva jav laurent thiry uha enseignant ensisa ecole school national alsace programmation objet approche mulhouse france java object programming oriented
Java jva jav laurent thiry uha enseignant ensisa ecole school national alsace programmation objet approche mulhouse france java object programming oriented