A
Arne Vajhøj
You would do the Java community a great service by posting two
snippets:
one coded the Smith Barney way with anonymous classes and another with
a rough approximation to the new closures.
Anonymous class:
ArrayList<String> lst = new ArrayList<String>();
lst.add("A");
lst.add("BB");
lst.add("CCC");
Collections.sort(lst, new Comparator<String>() {
public int compare(String s1, String s2) {
return -s1.compareTo(s2);
}
});
for(String s : lst) {
System.out.println(s);
}
Java 8 lambda:
import java.util.ArrayList;
import java.util.Collections;
public class Lambda {
public static void main(String[] args) {
ArrayList<String> lst = new ArrayList<String>();
lst.add("A");
lst.add("BB");
lst.add("CCC");
Collections.sort(lst, (s1,s2)-> -s1.compareTo(s2));
for(String s : lst) {
System.out.println(s);
}
}
}
Arne