Created
May 25, 2015 13:41
-
-
Save zzt93/6ec224f7a334b0de8530 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.