Skip to content

Instantly share code, notes, and snippets.

@zzt93
Created May 25, 2015 13:41
Show Gist options
  • Save zzt93/6ec224f7a334b0de8530 to your computer and use it in GitHub Desktop.
Save zzt93/6ec224f7a334b0de8530 to your computer and use it in GitHub Desktop.
package lambda;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
/**
* Created by zzt on 5/25/15.
* <p>
* Description:
*/
public class ComparatorFa {
public static Comparator<String> comparator1() {
return (o1, o2) -> {
Double d1 = Double.parseDouble(o1);
Double d2 = Double.parseDouble(o2);
return d1.compareTo(d2);
};
}
public static Comparator<String> comparator2() {
return (o1, o2) -> {
Double d1 = Double.parseDouble(o1);
Double d2 = Double.parseDouble(o2);
return d1.compareTo(d2);
};
}
public static Comparator<String> comparator3() {
return (o1, o2) -> {
Double d1 = Double.parseDouble(o1);
Double d2 = Double.parseDouble(o2);
return d1.compareTo(d2);
};
}
public static void main(String[] args) {
ArrayList list = new ArrayList<>();
list.add(1.9);
list.add(1.2);
Collections.sort(list, comparator1());
}
}
@zzt93
Copy link
Author

zzt93 commented May 25, 2015

Notice that I doesn't add a type parameter to this list for in some place of real project (like DefaulRowSorter in swing, in my case) I can't using type parameter, which may hide some problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment