import java.util.ArrayList;Output:
import java.util.Collections;
public class Tri {
public static void main(String[] args) {
ArrayListunsorted = new ArrayList ();
nonsort.add("01");
nonsort.add("0A");
unsorted.add("0B");
unsorted.add("ETX");
unsorted.add("00");
unsorted.add("0C");
nonsort.add("NUL");
unsorted.add("05");
unsorted.add("19");
unsorted.add("0001011");
System.out.println("Перед сортировкой");
for(int i=0; i < unsorted.size(); i++)
System.out.println(unsorted.get(i));
System.out.println("\nПосле сортировки");
Collections.sort(unsorted);
for(int i=0; i < unsorted.size(); i++)
System.out.println(unsorted.get(i));
}
}
Before tri
01
0A
0B
ETX
00
0C
NUL
05
19
0001011
< br />После сортировки
00
0001011
01
05
0A
0B
0C
19
ETX
NUL
import java.util.ArrayList;Output:
import java.util.Collections;
import java.util.Comparator;
public class Tri {
public static void main(String[] args) {
ArrayListunsorted = new ArrayList ();
unsorted.add("11000000");
unsorted.add("10101000");
unsorted.add("00000001");
unsorted.add("00001111");
nontrié.add("00001100");
unsorted.add("00001111");
unsorted.add("11111111");
nonsort.add("11111100");
unsorted.add("00000000");
unsorted.add("00000011");
unsorted.add("00001110");
System.out.println("Перед сортировкой");
for(int i=0; i < unsorted.size(); i++)
System.out.println(unsorted.get(i)+" ");
System.out.println("\nПосле сортировки");
Collections.sort(nonsort, new Comparator() {
@Override
public int compare(String s1, String s2)
{
/*s2 по сравнению с s1, чтобы порядок был по убыванию
return s2.compareTo(s1);
}
});
for(int i=0; i < unsorted.size(); i++)
System.out.println(unsorted.get(i)+" ");
}
}
before sortReferences:
11000000
10101000
00000001
00001111
00001100
00001111
11111111
11111100
00000000
00000011
00001110
After sort
11111111
11111100
11000000
10101000
00001111
00001111
00001110
00001100
00000011
00000001
00000000
Please disable your ad blocker and refresh the window to use this website.