all tasks
This commit is contained in:
parent
b83f433714
commit
68f8f3e56b
14735 changed files with 178959 additions and 0 deletions
|
|
@ -0,0 +1,20 @@
|
|||
import java.util.Comparator;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class Test {
|
||||
public static void main(String[] args) {
|
||||
String[] strings = {"Here", "are", "some", "sample", "strings", "to", "be", "sorted"};
|
||||
|
||||
Arrays.sort(strings, new Comparator<String>() {
|
||||
public int compare(String s1, String s2) {
|
||||
int c = s2.length() - s1.length();
|
||||
if (c == 0)
|
||||
c = s1.compareToIgnoreCase(s2);
|
||||
return c;
|
||||
}
|
||||
});
|
||||
|
||||
for (String s: strings)
|
||||
System.out.print(s + " ");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
import java.util.Comparator;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class ComparatorTest {
|
||||
public static void main(String[] args) {
|
||||
String[] strings = {"Here", "are", "some", "sample", "strings", "to", "be", "sorted"};
|
||||
|
||||
Arrays.sort(strings, (s1, s2) -> {
|
||||
int c = s2.length() - s1.length();
|
||||
if (c == 0)
|
||||
c = s1.compareToIgnoreCase(s2);
|
||||
return c;
|
||||
});
|
||||
|
||||
for (String s: strings)
|
||||
System.out.print(s + " ");
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue