package test.collections; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; public class Test01 { public static void main(String[] args){ //Set<String> songs = new HashSet<String>(); List<String> songs = new ArrayList<String>(); Collections.addAll(songs, "冷雨夜","海阔天空","love in the rain","海洋"); //排序 Collections.sort(songs); //随机排序 Collections.shuffle(songs); //倒序 Collections.reverse(songs); //交换顺序 Collections.swap(songs, 2, 3); printList(songs); } public static void printList(Collection<String> c){ for(String str:c){ System.out.println(str); } } }