文字列配列のソートと逆シーケンス

2350 ワード

 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