1 import java.util.Arrays;
 2 import java.util.Collections;
 3 import java.util.List;
 4 
 5 public class SortDemo {
 6 
 7     public static void main(String[] args) {
 8     String[] suits = { "Hearats", "Diamonds", "Clubs", "Spades" };
 9 
10     List<String> list = Arrays.asList(suits);
11     System.out.printf("Unsorted array elements: %s%n", list);
12 
13     Collections.sort(list);
14     System.out.printf("Sorted array elements: %s%n", list);
15     
16     Collections.sort(list, Collections.reverseOrder());
17     System.out.printf("Reverse sorted array elements: %s%n", list);
18     } // end method main
19 } // end class SortDemo

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-14
  • 2022-12-23
  • 2021-12-08
  • 2021-08-25
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案